Extract numbers from string (Regex C++)

后端 未结 1 1972
遇见更好的自我
遇见更好的自我 2021-01-26 07:15

let\'s say i hve a string S = \"1 this is a number=200; Val+54 4class find57\"

i want to use Regex to extract only this numbers:



        
1条回答
  •  再見小時候
    2021-01-26 07:29

    Just use word boundaries. \b matches between a word character and a non-word character.

    \b\d+\b
    

    OR

    \b[0-9]+\b
    

    DEMO

    Escape the backslash one more time if necessary like \\b\\d+\\b or \\b[0-9]+\\b

    0 讨论(0)
提交回复
热议问题