Looking for a regex to match a gmail plus address

前端 未结 7 1401
梦如初夏
梦如初夏 2021-01-25 08:25

Im using this currently :

/^(.*)\\+(.*)@gmail.com/

(I\'m capturing the text before and after the plus sign in a group)

and it works in most

相关标签:
7条回答
  • 2021-01-25 08:52

    You can use [] with ^ (all the chars but...) e.g.

    echo 'aaa++++bbb@gmail.com' | perl -p -e 's/^([^\+]*)\+(.*)@gmail.com/$1/'
    
    0 讨论(0)
  • 2021-01-25 08:53

    (.*?)\++(.*?)@gmail.com should work.

    0 讨论(0)
  • 2021-01-25 08:54
    [a-zA-Z0-9]{1,}[\+]{0,}[a-zA-Z0-9]{0,}@gmail.com
    
    0 讨论(0)
  • 2021-01-25 08:57

    If you don't care about validating the first portion of the address (prior to any '+') you could go with /^([^+]+)(:?+[^+]*)*@gmail.com/ to just the first part.

    You may want to do better validation on that to ensure that it is a "valid" account format, according to whatever rules are set forth by RFC.

    edit -- asterisks were making a bold statement.

    0 讨论(0)
  • 2021-01-25 08:58

    you need to escape the + sign : /^(.+?)\++(.+?)@gmail.com/

    EDIT : your post was misformatted : your + is already escaped

    0 讨论(0)
  • 2021-01-25 08:59

    You are not properly detecting the +. Use something like this: ^([^+]+)[+]+([^+]+)@gmail.com

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