regex extract email from strings

前端 未结 7 1468
陌清茗
陌清茗 2020-12-01 16:25

I want to know if by using regular expressions I am able to extract emails from the following strings?

The following RE pattern is .*@.*match with all st

7条回答
  •  情深已故
    2020-12-01 17:08

    [a-zA-Z0-9-_.]+@[a-zA-Z0-9-_.]+ worked for me, you can check the result on this regex101 saved regex.

    It's really just twice the same pattern separated by an @ sign.

    The pattern is 1 or more occurences of:

    • a-z: any lowercase letter
    • A-Z: any uppercase letter
    • 0-9: any digit
    • -_.: a hyphen, an underscore or a dot

    If it missed some emails, add any missing character to it and it should do the trick.

    Edit

    I didn't notice it first, but when going to the regex101 link, there's an Explanation section at the top-right corner of the screen explaining what the regular expression matches.

提交回复
热议问题