1

We have an application that we suspect is getting spam/clickfarm email addresses signing up. A lot of them follow the pattern:

For example,

RegEx

/(\w+)(\d+)(\w+)/g gets me close to what I want but also captures numbers at the end of the string

4
  • Like /(\w+?)(\d+)(\w+)/g? What numbers are there at the end of the string? Commented Oct 17, 2016 at 17:51
  • That's closer, but still captures ones like [email protected] Commented Oct 17, 2016 at 17:52
  • 1
    Then /([^\W\d]+)(\d+)([^\W\d]+)/g should work. Commented Oct 17, 2016 at 17:53
  • You rock. Thank you. Commented Oct 17, 2016 at 17:53

1 Answer 1

1

The \w shorthand character class also matches digits and letters. You may either replace it with [a-zA-Z] or subtract the digits using a reverse char class - [^\W\d].

Use either

([a-zA-Z]+)(\d+)([a-zA-Z]+)

(see demo) or an anchored version:

^([^\W\d]+)(\d+)([^\W\d]+)
^

See another demo. The ^ will anchor the pattern at the start of the string.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.