Match integer parts of numbers

How do I match

13
1337

in

<b>Level:</b> 13.37<br />
<b>Level:</b> 1337<br />

using regex?

This is what I tried:

/<b>Level:<\/b> ([^<]*)<br \/>/gm

See RegEx101.

1 answer

  • answered 2018-07-11 07:11 Wiktor Stribi┼╝ew

    Please consider using an HTML parser to actually parse out plain texts from HTML code.

    If you have a list of strings like those in the question, and they are always in that format, the use of regex may be justified, and you may use

    /<b>Level:<\/b>\s*(\d+)[^<]*<br\s*\/>/g
    

    See this regex demo

    Details

    • <b>Level:<\/b> - a literal <b>Level:</b> substring
    • \s* - 0+ whitespaces
    • (\d+) - Group 1: one or more digits
    • [^<]* - 0+ chars other than <
    • <br\s*\/> - <br followed with 0+ whitespaces, and then /> substring.