So here’s an example string:
CN=John Doe,OU=IT,OU=Management Support Services,OU=Divisions,OU=Accounts,DC=company,DC=com
I only need to get the first name out of this string. In this case the name being John Doe. I can’t hard code a number of characters in as the names there can vary in length.
Basically I need to select the string after CN= and then end it at the first comma.
The first number can always be 3 characters since the CN= is always there. Is there anyway for me to use the first comma as the end point?
I’m trying to do something like this.
let name = reports[i].mgrdn;
let result = name.split(3, ",")
Any help would be appreciated. Even just a suggestion about what method to use.
4
Answers
You can do this by using the indexOf method and then slice
This will give you what you need.
Of course you should probably validate the format is what is expected too.
As @freedomn-m says…
Step-by-step:
If you want to use regex:
https://regex101.com/r/i4p0Ks/1
If you need to get more than just the first you can convert it in to query params.