28.10.2021 Views

Python Tutorial ( PDFDrive )

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Backreferences:

This matches a previously matched group again:

Example

([Pp])ython&\1ails

(['"])[^\1]*\1

Alternatives:

Example

python|perl

rub(y|le))

Description

Match python&pails or Python&Pails

Single or double-quoted string. \1 matches whatever the 1st group matched . \2 matches

whatever the 2nd group matched, etc.

Description

Match "python" or "perl"

Match "ruby" or "ruble"

Python(!+|\?) "Python" followed by one or more ! or one ?

Anchors:

This needs to specify match position.

Example

^Python

Python$

\APython

Python\Z

\bPython\b

\brub\B

Python(?=!)

Description

Match "Python" at the start of a string or internal line

Match "Python" at the end of a string or line

Match "Python" at the start of a string

Match "Python" at the end of a string

Match "Python" at a word boundary

\B is nonword boundary: match "rub" in "rube" and "ruby" but not alone

Match "Python", if followed by an exclamation point

Python(?!!)

Match "Python", if not followed by an exclamation point

Special syntax with parentheses:

Example

R(?#comment)

R(?i)uby

R(?i:uby)

rub(?:y|le))

Description

Matches "R". All the rest is a comment

Case-insensitive while matching "uby"

Same as above

Group only without creating \1 backreference

TUTORIALS POINT

Simply Easy Learning

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!