2021年3月7日星期日

Do not match if nothing exists between optional parenthesis

I'm attempting to parse group names from /etc/security/login-access.conf. We have a mixed environment of LDAP & AD machines. AD groups are encapsulated with parenthesis ().

I have the following regex that works to extract only the group name, however the only problem I am having with it is there is routinely a 'null' group and the regex returns a null & the ) characters:

Current regex:

/(?<=\+\s:\s[@\(])(.*?)(?=[\)]?\s:)/  

Sample /etc/security/login-access.conf:

+ : @ldapgroup1 : ALL  + : @ldapgroup2 : ALL  + : (@adgroup1) : ALL  + : (@adgroup2) : ALL  + : () : ALL          # <---This is the problematic entry.  

I'm not sure if or how to tune the regex to ignore an entry that contains nothing between the parenthesis. Any help is appreciated.

https://stackoverflow.com/questions/66523839/do-not-match-if-nothing-exists-between-optional-parenthesis March 08, 2021 at 11:07AM

没有评论:

发表评论