regex-greedy

Greedy means it will go towards the end of line and will NOT stop at first match if there are other matches available.

'.*'  = Greedy
'.*?' = Lazy

Lazy has extra character (?) in the regex syntax. Similarly you can use ‘+’ operator instead of ‘*’

'.+'  = Greedy
'.+?' = Non Greedy (also called Lazy, Reluctant)

‘+’ mean one or more characters
‘*’ mean zero or more characters

Advertisements
This entry was posted in Regular Expressions and tagged . Bookmark the permalink.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s