![]() |
Perl REGEX - How do extract a string in a line?
Hi Guys,
In the following line: cn=portal.090710.191533.428571000,cn=groups,dc=mp, dc=rj,dc=gov,dc=br I need to extract this string: portal.090710.191533.428571000 As you can see this string always will be bettween "cn=" and "," strings. Someone know one regular expression to extract this string? Any help will be very much appreciated Best Regards Pierre |
Re: Perl REGEX - How do extract a string in a line?
MyString = "1234567890"
startPos = 3 charCount = 4 Print Mid$(MyString,startPos,charCount) ' Prints "3456" |
Re: Perl REGEX - How do extract a string in a line?
Similarly,
cn=portal.090710.191533.428571000,cn=groups,dc=mp, dc=rj,dc=gov,dc=br startPos = 4 charCount = 33 Print Mid$(MyString,startPos,charCount) |
Re: Perl REGEX - How do extract a string in a line?
Hi naimish,
I donīt understand your idea... I have the following code: if( /cn=/ ) { $result = $_; $result =~ s/^cn=([^,]*?),//; <-- MY REGEX EXPRESSION } return $result in this case your REGEX is returning cn=groups,dc=mp,dc=rj,dc=gov,dc=br I need the opposite result. I think a REGEX where in the first time remove the string cn= so the result string will be portal.090710.191533.428571000,cn=groups,dc=mp,dc= rj,dc=gov,dc=br The second REGEX will remove the entire string cn=groups,dc=mp,dc=rj,dc=gov,dc=br To be lefting only the needed string portal.090710.191533.428571000 Can you help me? Regards Pierre |
Re: Perl REGEX - How do extract a string in a line?
You could try something like:
@res = ($line =~ /cn=(.*?),/ig) print $res[0]; |
Re: Perl REGEX - How do extract a string in a line?
Code: Perl
|
Re: Perl REGEX - How do extract a string in a line?
my $str="cn=portal.090710.191533.428571000,cn=groups, dc=mp, dc=rj,dc=gov,dc=br";
if($str=~/cn=(.*),cn=/) { print $1; } |
Re: Perl REGEX - How do extract a string in a line?
$a='cn=portal.090710.191533.428571000,cn=groups,dc =mp, dc=rj,dc=gov,dc=br';
$a=~ /p[\w.]*/; print"$&\n"; |
| All times are GMT +5.5. The time now is 09:32. |