Find numbers after specific text in a string with RegEx

后端 未结 3 1254
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 15:00

I have a multiline string like the following:

2012-15-08 07:04 Bla bla bla blup
2012-15-08 07:05 *** Error importing row no. 5: The import of this line faile         


        
3条回答
  •  臣服心动
    2020-12-03 15:42

    Try this expression:

    "Error importing row no\. (\d+):"
    

    DEMO

    Here you need to understand the quantifiers and escaped sequences:

    • . any character; as you want only numbers, use \d; if you meant the period character you must escape it with a backslash (\.)
    • ? Zero or one character; this isn't what do you want, as you can here an error on line 10 and would take only the "1"
    • + One or many; this will suffice for us
    • * Any character count; you must take care when using this with .* as it can consume your entire input

提交回复
热议问题