Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular expressions 1

Status
Not open for further replies.

dbgoose

IS-IT--Management
Sep 20, 2007
2
US
I am trying to match a pattern from and Active Directory extract. I have tried numerous things. In words what I want to match is "Anthing between the CN= and the following , " When I use the anything construct . I end up getting the entire text. Of course I can use exact patterns such as \w+\s\w+|\w+\s\w+-\w+

but obviously I wont know all of the possible combinations so I want to be able to match anything between the CN= and the following , and repeat this for the whole string. Following is an example string (names have been changed of course). Thanks in advance for any help!

"CN=Some group,CN=Users,DC=somecompany,DC=com","CN=John,OU=Service Accounts,DC=somecompany,DC=com;CN=Mickeymouse,OU=Service Accounts,DC=somecompany,DC=com;CN=Danny,OU=Service Accounts,DC=Somecompany,DC=com;CN=Sandra gather-brown,OU=Finance Accounting,OU=St Petersburg,DC=Somecompany,DC=com;CN=Jon t Smith,OU=NorthCarolina,DC=Somecompany,DC=com;CN=Jane Jones,OU=SouthCarolina,DC=Somecompany,DC=com;CN=Samantha Johnson,CN=Users,DC=Somecompany,DC=com;CN=Exch service,CN=Users,DC=Somecompany,DC=com;CN=huay-son-young,CN=Users,DC=Somecompany,DC=com;CN=Sam Johnson,CN=Users,DC=Somecompany,DC=com;CN=Sampson,CN=Users,DC=Somecompany,DC=com;
CN=David Blythe,CN=Users,DC=Somecompany,DC=com;CN=William Jones,CN=Users,DC=Somecompany,DC=com;CN=some-name-person-whatever,CN=Users,DC=Somecompany,DC=com;CN=Jim Smith,CN=Users,DC=Somecompany,DC=com"
 
Code:
@matches = $string =~ /CN=([^,]+),/g;

where $string is the string you posted above. Add an "s" after the "g" at the end of the regexp if there are newlines in the string.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Thanks Kevin I really appreciate your response it was perfect!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top