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
  • 34,719
  • 24
  • 185
  • 251
JustAGuy
  • 4,493
  • 9
  • 37
  • 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,888
  • 9
  • 23
  • 37