I have the following string ...
CN=KendallLDAPTEST Weihe,OU=CORPUSERS,OU=CORP,DC=int,DC=appriss,DC=com
and I need to extract KendallLDAPTEST Weihe
in other words I need to extract all string data between the first = and the first ,
You can simply break the string apart using split on , to first produce an array of key=value pairs, and then split those pairs on =.
str = 'CN=KendallLDAPTEST Weihe,OU=CORPUSERS,OU=CORP,DC=int,DC=appriss,DC=com'
pairs = str.split(',').map { |pair| pair.split('=') }
# => [["CN", "KendallLDAPTEST Weihe"], ["OU", "CORPUSERS"], ["OU", "CORP"], ["DC", "int"], ["DC", "appriss"], ["DC", "com"]]
pairs.first[1]
# => "KendallLDAPTEST Weihe"
This is somewhat naive in that it will not work if any of your data contains escaped = or , characters.
I'd use:
str = "CN=KendallLDAPTEST Weihe,OU=CORPUSERS,OU=CORP,DC=int,DC=appriss,DC=com"
str[/=([^,]+)/, 1] # => "KendallLDAPTEST Weihe"
By default the regular expression will find the first match then stop. This simply finds the first =, then captures all characters that are not , until the first ',' and returns it.
If the text you are trying to capture is always appearing on the same index you can use this:
the_text[3...22]