bsd
bsd

Reputation: 6173

How to regex one word from escaped and closed parenthesis?

I am trying to get "loginuser" value from this line. Please suggest

my $ln = CN=xuser\\,user(loginuser),OU=Site-Omg,OU=Accounts_User,OU

    if (/ln: (\S.*\S)\s*$/)
       { print $1; }

Upvotes: 0

Views: 23

Answers (1)

123
123

Reputation: 11216

This will work

use strict;
use warnings;

my $ln = qq{CN=xuser\\,user(loginuser),OU=Site-Omg,OU=Accounts_User,OU};

print $1 . "\n" if $ln =~ /\(([^)]*)/

Things to note

I have used strict and warnings to show any errors in the script( would have been very useful for your original)
I have used qq{...} to quote the original string
I have ended the line with ;
I have performed the regex match on $ln instead of $_ using $ln =~ ...
I have written correct regex to get the match.

Upvotes: 3

Related Questions