regex


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=(.*?)\]

Related Links

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

Categories

HOME
asp.net-identity
groovy
svg
simulated-annealing
dynamics-crm-365
spring-roo
bolt-cms
chronicle
windows-runtime
open-source
stripe-payments
visual-studio-2012
jbpm
http2
predictionio
zipfile
mobilefirst-adapters
oracle-ucm
scope
sonata-admin
vulkan
oracle-agile-plm
installer
jquery-selectors
helpers
oracle11gr2
servlet-filters
teamcity-9.0
rgdal
ibm-datapower
line-breaks
addthis
weather-api
android-arrayadapter
arduino-esp8266
svn2git
stl
kubernetes-go-client
breakpoint-sass
panel-data
imageshack
edit-distance
outlook-vba
dwm
jdom-2
microsoft-translator
transpose
runc
brainfuck
google-slides
requirements-management
manifoldjs
unityscript
android-identifiers
haste
jvm-arguments
breach-attack
perspective
building
ocsp
insert-update
visual-build-professional
xmllint
rras
schematiq
id3
strace
balana
skrollr
android-gpuimageview
push-api
cocoon-gem
equinox
ppl
bonfire
gem
gem5
google-swiffy
fastparse
smarty2
gitattributes
sigkill
json-web-token
gdk
monk
eventmachine
team-explorer-everywhere
xacml3
dirpagination
asp.net-apicontroller
libtorrent-rasterbar
emitmapper
libnids
mips64
xcache
nsimageview
jcycle
cakephp-2.1
blackberry-cascades
force.com
letter-spacing
objcopy
gemstone
jquery-pagination
staging
nscollectionviewitem
jdic
system-tray
mkmapviewdelegate

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App