bsd
bsd

Reputation: 6173

How to perl regex ldap values?

I need to extract two values from given output.

kat\, mith(mkat),OU=Site-SJN,OU=Accounts,OU

I am looking for these two output values

$user = kat\, mith(mkat)
$site = Site-SJN

I've tried these options. Please suggest to get above two values.

$user =~ s/^.*?://;
$user =~ s/^*.?OU=//;
$site =~ s/^Site?/;

Upvotes: 0

Views: 51

Answers (1)

Borodin
Borodin

Reputation: 126742

You give only the barest of information, so I can only tell you what will work for that one line of input data

Here's my best guess about what will work for you, but I am pretty certain you're going to come back with another line that doesn't do quite what you want

use strict;
use warnings 'all';
use feature 'say';

my $s = 'kat\, mith(mkat),OU=Site-SJN,OU=Accounts,OU';

my ($user) = $s =~ /^([^,]*,[^,]*)/;
my ($site) = $s =~ /\bOU=(Site[^,]*)/;

say $user;
say $site;

output

kat\, mith(mkat)
Site-SJN

Upvotes: 2

Related Questions