0

I know this question has been asked many times, but when I attempted to use the accepted answer that I found here, it does not work, so I assume I'm missing something.

I was attempting to match the Mrs. in the string Rothschild, Mrs. Martin (Elizabeth L. Barrett) using this regular express:

.*, (.*\.).*

But this does not work because of the L.. I then attempted to add the ? a number of different ways, but it still matches all the way to L.. Some things I tried:

.*, (.*\.?).*
.*, (.*\.*?).*
.*, (.*\.+?).*
.*, (.*\.??).*

But none of these work. Can anyone see what I am missing here?

Regex Fiddle

Community
  • 1
  • 1
Abe Miessler
  • 82,532
  • 99
  • 305
  • 486

1 Answers1

1

Put ? after the * which was present inside the capturing group. .* is greedy and eats up characters as many as possible. You need to add a quantifier ? after the * to do a shortest possible match.

.*, (.*?\.).*

DEMO

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274