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&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.
explanation:
(^|[^"])finds beginning of line or character other double quote; necessary make sure you're not inside double quote, match ignored.http:\/\/www.youtube.com\/, of course, finds "http://www.youtube.com/".[^\s"]*finds characters to, not including, next space (\s) or double quote (").- 2 , 3 framed in parentheses, forming second match group, looking for.
Comments
Post a Comment