sindresorhus / email-regex

Regular expression for matching email addresses
MIT License
134 stars 17 forks source link

Add options to match start or end of input #4

Closed akonsu closed 7 years ago

sindresorhus commented 7 years ago

Why? What's your use-case?

akonsu commented 7 years ago

I use this regex in a call to Codemirror's stream.match API (https://codemirror.net/doc/manual.html#modeapi) It requires that the pattern has starting anchor ^ so that it can match a token at the beginning of the stream.

sindresorhus commented 7 years ago

Sorry about the delay. Alright. Will merge if you add a couple of tests ;)

sindresorhus commented 7 years ago

Ping @akonsu :)

sindresorhus commented 7 years ago

Closing for lack of response.

kevva commented 7 years ago

Another way is to just wrap it:

const regex = new RegExp(`^${emailRegex().source}`);

regex.match('unicorn hello@example.com');
//=> false

regex.match('hello@example.com');
//=> true