i am trying to extract the text “abcdef” from the following html using regex:
<a href="xyz.com" rel="bookmark" title="hello_world">abc def</a>
i am trying this pattern
$pattern = "<a href=(.*?) rel='bookmark' title=(.*?)>(.*?)</a>"
it would be helpful if anyone help me to figure out the pattern . I am using PHP .
thanks
Use
DOMDocumentinstead. Specifically,DOMDocument::loadHTML. Your life will be much easier.You could use a pattern like the following, but I really don’t recommend using regexes to manipulate HTML:
I also noticed that in your regular expression you have
rel='bookmark'whereas the original string hasrel="bookmark". This is probably why your original regex is not working.