0

I have the following string:

EN=sdfsdf, CN=User Name, CN=Users, DC=domain, DC=co, DC=il

I need to return the first string that starts with "CN=" and ends with an ",". In this case I need to return "User Name".

'CN=.*,' returns "CN=User Name, CN=Users, DC=domain, DC=co,"

How can I get the just the first occurrence?

Cœur
  • 37,241
  • 25
  • 195
  • 267
JustAGuy
  • 5,151
  • 11
  • 41
  • 55

1 Answers1

0

You will need the non-greedy option in your Regex:

CN=.*?,

See also How can I write a regex which matches non greedy?

rollstuhlfahrer
  • 3,988
  • 9
  • 25
  • 38