Combination of special characters in regex

Combination of special characters in regex

Special characters substring variation Example
.

dot. matches any character

*

star / asterisk. the resulting RE to match 0 or more repetitions of the preceding RE, as many repetitions as are possible.

re.search (“ab*”, substring)

substring = “nerpb”

None
substring = “nabrp” <_sre.SRE_Match object at 0x___>

retval.group(0) → a

substring = “na brp” <_sre.SRE_Match object at 0x___>

retval.group(0) → a

substring = “nabrp” <_sre.SRE_Match object at 0x___>

retval.group(0) → ab

. substring = “nabbbrp” <_sre.SRE_Match object at 0x___>

retval.group(0) → abbb

. substring = “nababrp” <_sre.SRE_Match object at 0x___>

retval.group(0) → ab

retval.group(1) → outside index

Greedy qualifiers:
*     more than 0

+     more than 1

?     0 or 1

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s