In general, the matching of regular expressions is greedy. For example, the following example:
String: src=” http://www.bloghome.cn/1.mp3 ” type=”application/x-mplayer2″ ….
Required results: http://www.bloghome.cn/1.mp3
If the matching expression is written as: / SRC = “(. *)” /, you will not get the correct result because the matching of the last double quotation mark is greedy.
Solution: write the matching expression as:
/src=”(.*)”.?/
In the above expression, “.? is a non greedy pattern matching. That is, as long as a character is followed by a specified number of special characters, the matching is a non greedy pattern.