-1

I need help with a regex...

I have $info = uid=myuid.name,ou=people,dc=my-dc,dc=fr

I'd like to extract the myuid.name into a group

preg_match("my regex", $info, $match);

In order to get the uid in $match

The last part of $info can change, for example:

,ou=people,dc=my-dc,dc=fr
,ou=people,dc=other-dc,dc=fr
,ou=people,dc=my-dc2,dc=fr

Thanks for your help!

0xPunt
  • 313
  • 1
  • 4
  • 21

1 Answers1

0

/(?:^|.*,)uid=(.*?)(?:,.*$|$)/ should do what you're after. The one capture group will grab the uid value and nothing else, regardless of what comes before or after.

The non-capturing group at the start will match either the start of the string (for when uid is the first value as in your example) or everything up to a comma immediately before uid for when other values come first.

The one at the end will match either all values that come after the uid, or the end of the string for if the uid is the last value.

Josh
  • 424
  • 2
  • 10