Few notes when using regular expressions:
.* match is greedy and will match as many as possible.
For example regex: “<Tag>.*</Tag>” will match full string “<Tag> some text </Tag> <Tag> some other text </Tag>” and not “<Tag> some text </Tag>” as you would expect.
While .*? is reluctant and will match only “<Tag> some text </Tag>”
Another thing to note is .* and .*? matches only string char and exclude line characters. For example if input is:
“<Tag> some \n text </Tag> <Tag> some other text </Tag>”
Then above expression will not match, to specify that .(dot) matches line characters too, you have to specify
DOT_ALL flag using (?s) like “(?s)<Tag>.*</Tag>”
No comments:
Post a Comment