-3

Need a RegEx to match 2 consecutive repetitive words on either side of a space

I am doing a data cleanse, and in this case it is the First Name field.

So I want to find a Regex that will find invalid First Names.

So things like:

David David  

Steve Steve

Mary Mary

Basically I need to find entries where some sort of data entry issues have occurred and a persons' first name has been entered 2x into the First Name field.

Hopefully this clarifies ))

Please help, I'm stuck.

Tnx

Uri Agassi
  • 35,245
  • 12
  • 68
  • 90
  • Please consider bookmarking the [Stack Overflow Regular Expressions FAQ](http://stackoverflow.com/a/22944075/2736496) for future reference. Welcome! – aliteralmind Apr 25 '14 at 12:47

1 Answers1

1

For that use backreferences:

(\w+) \1

Demo

The \number backreferences are used to refer to captured groups in the expression. In this case, the first captured group was (\w+) and therefore, the above regex will match a string which is two same words separated by a space.

sshashank124
  • 28,066
  • 8
  • 58
  • 71
  • Very nice! Seems to work for what I'm looking for... I could have sworn it would have been a more complicated regex than that... I am new to it tho.. thanks a bunch mate! – user3571977 Apr 25 '14 at 12:33