Click here to Skip to main content
15,300,537 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a string such as :

"For Sports watch @@video:[anything]$$ For Entertainment watch

Can anyone help me to generate a regular expression to retrieve all
@@video:[anything]$$ kind of links? i.e. I require all text starting from @@video upto $$

P.S : There can be any special characters like @,$ etc. in anything of

1 solution

You haven't mentioned which language you're using, but something like this should work:
jaket-cp 8-Oct-14 10:32am
I wanted to ask, what does the +? do and could you not use the + instead.
Did some reading, and non-greedy came up :)
Also I believe the question was to include all special characters,
Here is your example modified: /\@\@video(.+?)\$\$/g
Richard Deeming 8-Oct-14 10:35am
+? means "match at least one, but as few as possible". Without it, if you were using .+, the match would be extended until the end of the last @@video[...]$$ tag in the input string.

You could use "." to match any character, but I chose to use "[^\]]" to match any character except a closing square bracket. Depending on the regex engine, this might be slightly faster.
jaket-cp 8-Oct-14 10:46am
Thanks for the explanation.

I believe you answer is 100% correct, just the ambiguity in the question:
"i.e. I require all text starting from @@video upto $$"

Also how do you highlight your text within a comment - or is that in a how to somewhere? Thanks
Richard Deeming 8-Oct-14 10:47am
The highlight is just standard HTML markup - in this case, <code>...</code> tags around the text. :)
jaket-cp 8-Oct-14 10:49am
cool didn't know you could use HTML in the comments - thanks :)
Maciej Los 8-Oct-14 11:45am
Good job, +5!

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