Here are my potential inputs:
What I want to do is extract the @muck.co email address.
What I have tried is:
\s.*@muck.co
The problem is that this only grabs an email address if it is preceded by a space (so it would only match the second example input above). . . How would I write a Regex expression to match either inputs?
CodePudding user response:
\s
matches for a space, so you should wanted to use something like [^\s]*@muck.co
- this means any number of not space caracters. []
- for a set of symbols, ^
- for negate effect.
It does not work for me, because \s
in my regex flavour seems to not contain regular space, but this works [^[:space:]]\ @muck\.co
. Also \
instead of *
for one or more non-space characters instead of any number and escape dot \.
which unescaped stands for any single character.
CodePudding user response:
You can use a negated character class to not cross the @ and use either a word boundary at the end to prevent a partial word match:
[^\s@] @muck\.co\b