Regex within html tags

前端 未结 5 530
孤独总比滥情好
孤独总比滥情好 2021-01-24 10:19

I would like to parse the HD price from the following snipper of HTML. I am only have fragments of the html code, so I cannot use an HTML parser for this.



        
5条回答
  •  余生分开走
    2021-01-24 10:38

    You can use this regex:

    \d+(?:\.\d+)?(?=\D+HD Version)
    
    • \D+ skips ahead of non-digits in a lookahead, effectively asserting that our match (19.99) is the last digit ahead of HD Version.

    Here is a regex demo.

    Use the i modifier in the regex to make the matching case-insensitive and change + to* if the number can be directly before HD Version.

提交回复
热议问题