I am trying to use Regular Expressions to decode some HTML I retrieve from a webpage.
I want to transform some <iframe>
tags into links.
The code I'm using should be working fine according to me and some testprograms, however when I run it on my android device it does not find any matches (where as in the test programs it does).
The regular expression I am using is as follows (keep in mind I'm coding in Java, so I need to escape the escape character as well):
String regularExpression = "<iframe.+?src=\\\\?(\\S+).+?(><\\\\?/iframe>|\\\\?/>)";
String replacement = "<a href=$1>Youtube</a>";
input.replaceAll(regularExpression, replacement);
From what I can gather from this it should replace all <iframe>
tags that have a src
attribute to hyperlinks with that source. However when I feed the following input to it, it does nothing with it:
<iframe src=\"http:\/\/www.youtube.com\/embed\/s6b33PTbGxk\" frameborder=\"0\" width=\"500\" height=\"284\"><\/iframe>
The response is simply the exact same text, only with the escape-characters removed:
<iframe src="http://www.youtube.com/embed/s6b33PTbGxk" frameborder="0" width="500" height="284"></iframe>
Can someone help me and explain what I'm doing wrong? I only started learning Regular Expressions yesterday, but I just can't for the life of me figure out why this doesn't work.