Regex to differentiate between two types of strings -


i have wordpress xml file have find , replace on switch plain youtube urls youtube embed code. can't wildcard search because xml file has anchor links youtube videos need remain are.

so, have find strings this:

http://www.youtube.com/watch?v=qo7xclfbipi&list=plz0rlqy-mngfq1i67mjgmh-7kfltr4nei 

and this:

http://www.youtube.com/watch?v=qo7xclfbipi 

and replace them this:

<iframe width="640" height="360" src="https://www.youtube.com/embed/qo7xclfbipi?list=plz0rlqy-mngfq1i67mjgmh-7kfltr4nei"  frameborder="0" allowfullscreen></iframe> 

but not match this:

src="http://www.youtube.com/embed/videoseries?list=plz0rlqy-mngfq1i67mjgmh-7kfltr4nei" 

or this:

<a href="http://www.youtube.com/watch?v=czzlv0ofamc&amp;list=plz0rlqy-mngfq1i67mjgmh-7kfltr4nei"> 

i'm thinking youtube link isn't wrapped in quotes it. appreciated. think regex search , replace in coda i'm not equipped knowledge in area.

cheers.

how (^|[^"])(http:\/\/www.youtube.com\/[^\s"]*), , use second match group.

see example here

explanation:

  1. (^|[^"]) finds beginning of line or character other double quote; necessary make sure you're not inside double quote, match ignored.
  2. http:\/\/www.youtube.com\/, of course, finds "http://www.youtube.com/".
  3. [^\s"]* finds characters to, not including, next space (\s) or double quote (").
  4. 2 , 3 framed in parentheses, forming second match group, looking for.

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -