Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to get the type and id of videos from a big text, so to do that I used Regex with following expression

video\('(?<type>.*),(?<id>.*)'\);



now if the text is something like

video('abc,efg');
some text
video('abc,efg');
some text
video('abc,efg');
some text
video('abc,efg');


it works

but if text has single line, like
video('abc,efg');some text video('abc,efg');some text video'abc,efg');some text 
video('abc,efg');


it doesn't work, returns wrong values...
Posted
Updated 6-Jan-10 5:29am
v2

.* is "greedy", but .*? is "lazy". The greedy version will find the longest match. The lazy version will find the shortest match. What you want here is the lazy version.

EDIT: Actually, your question marks should be fine. I forget what that construct does, but I've seen it before.




Edit by Asker :
the working one
video\('(?<type>.*?),(?<id>.*?)'\);


thanks
 
Share this answer
 
v3
Replace the .* with a statement that always rejects a '. Your regex will keep going on the line until it finds the last quote, not the next one. I forget what that is, but you can use expresso, which is easy to google, to help build and test regex.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900