Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Regex Help!!
summergs
I have spent HOURS trying to get this thing to work. Can someone enlighten me (before I destroy something)!
I have a contributor/approver with the standard format of: DOMAIN\user
In my case: cia-intercept\Bill
I am trying to strip everything except the user name, thus my result would be: Bill
I have tried a lot of different things including:
$getUser = $ARGV[$i];
#$filterUser = $getUser =~ m/^cia[-]intercept[\\](\S+)(?{$varUser=$^N})/i;
#$filterUser = $getUser =~ m/^a-z\-a-z\\(\S+)(?{$varUser=$^N})/i;
#$userID = $varUser;
$filterUser = $getUser =~ m/^a-z\-a-z\\(.*?).*$/;
$userID = $1;
I would greatly appreciate any help & many thanks!!!
Find more posts tagged with
Comments
Adam Stoller
(my $getUser = $ARGV[$i]) =~ s|^.*\\||;
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
summergs
fish. YOU are the man. THANK YOU!!
Adam Stoller
While I appreciate the accolade - this was a rather trivial issue (perl-wise) - I just happened to manage to see it before anyone else.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
jbonifaci
As always, there's more than one way to do it. But I prefer to match first and then assign the result of the match to a new variable, rather than assign the whole value to the variable and then strip out what you don't want:
my ($getUser) = $ARGV[$i] =~ m|\\([^\\]+)$|;
Just my $.02, for what they are worth.
Edit: Changed regex to get user instead of domain
.
Migrateduser
jbonifaci, I prefer that method, as well -- so, that solution should now come to $0.04.
Dave
Adam Stoller
Hmmm:
~/temp >
perl -le '(my $x = q(domain\username)) =~ s|^.*\\||;print $x;'
username
~/temp >
perl -le 'my $x = q(domain\username) =~ m|^([^\\]+)\\|;print $x;'
1
Perhaps I'm missing something - but your suggested method doesn't seem to end with the desired result...
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
Dwayne
The test
should
have been:
perl -le 'my
(
$x
)
= q(domain\username) =~ m|^[^\\]+\\(.*)|;print $x;'
which should produce the right result;
The original regex was wrong, but you were also missing the parens in your sample.
--
Current project: TS 5.5.2/6.1 W2K
jbonifaci
Haha, oops, yeah, I was getting the domain instead of the user, but the principle is still the same
.
herald10
How about:
my $myfile=qw{cia-intercept\Bill};
my($domain,$user)= split /\\/, $myfile;
jbonifaci
Fish,
As Dwayne said, you were missing the ()'s around $x. It returns an array of all of the backrefrences from your regex. So what you are getting back in the example is a 1 element array.
Adam Stoller
Okay - so there were several mistakes made - I suppose the fact that you need the parens makes it less favorable to me - not because I don't understand the need [I do] but because it's easy to forget the parens and the code remains syntactically correct but logically wrong.
However, I think we've beaten this horse into the ground by now (there are probably another dozen ways to achieve the desired results, but I don't think we need to figure them all out ...)
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com