Skip to content Skip to sidebar Skip to footer

Regex Against Markup After Xpath?

Have been searching for the solution to my problem now already for a while and have been playing around regex101.com for a while but cannot find a solution. The problem I am facing

Solution 1:

Regex is the wrong tool for parsing markup. You have a proper XML parsing tool, XPath, in hand. Finish the job with it:

This XPath,

strong[.='Name:']/following-sibling::text()[1]

when appended to your original XPath,

//body/div/table/tbody/tr/td/p[5]/strong[.='Name:']/following-sibling::text()[1]

will finish the job of selecting the text node immediately following the <strong>Name:</strong> label, as requested, with no regex hacks over markup required.

Solution 2:

You can try to match everything but tag markers:

(?<=<\/strong> )([^<>]*)(?= <br>)

Demo

Post a Comment for "Regex Against Markup After Xpath?"