Regex getting url string
I trying to get the youtube url between [link= and ] using this code. Why isn't it working? code (?<=[link=\s).*(?=\s]) text a very long text before this [link=http://www.youtube.com/watch?feature=player_embedded&v=Fh3knetKm5U]and some text here i need to get http://www.youtube.com/watch?feature=player_embedded&v=Fh3knetKm5U
What about simply: \[link=(.*?)\] Is there a reason you use lookbehinds? More importantly, this looks like you are planning to implement text formatting. Have you considered using libraries like markdown or ReST? Example using the above regex: >>> import re >>> p = re.compile(r'\[link=(.*?)\]') >>> txt = '''a very long text before this ... [link=http://www.youtube.com/watch?feature=player_embedded&v=Fh3knetKm5U]and some''' >>> p.findall(txt) ['http://www.youtube.com/watch?feature=player_embedded&v=Fh3knetKm5U']
You are using unnecessarily the lookahead and lookbehind. These can simply do for you \[link=(\S+)\] \[link=([^\]]*)\] \[link=(.+)\] \[link=(.*?)\]
In WordPress, how can I remove the parent page from my url?
Why isn't ModRewrite returning my regular expression as expected?
Regexp to selectively match email
Regex match two strings but not third (in random order)
Test but not select with regex
Pattern to delete lines causes the whole contents of the file to be deleted in Sed
Using a regex in a conditional vs. an outright awk/sed?
Regex for a valid month
Remove everything except a certain pattern
Hubot Not Responding to regex
RegExp to find first letter of words before #
Creating Index based on another field in logstash
Bug in R's grepl? [closed]
Regular Expression Google Form only numbers in a range
MS Word VBA macro to search and replace (Regex)
Repeat capture group ignoring whitespaces