Thursday, 15 May 2014

perl regex replace only part of string -



perl regex replace only part of string -

i need write perl regex convert

site.company.com => dc=site,dc=company,dc=com

unfortunately not able remove trailing "," using regex came below. of course of study remove trailing "," in next statement prefer handled part of regex.

$data="site.company.com"; $data =~ s/([^.]+)\.?/dc=$1,/g; print $data;

this above code prints:

dc=site,dc=company,dc=com,

thanks in advance.

$data =~s/\./,dc=/g&&s/^/dc=/g;

tested below:

> echo "site.company.com" | perl -pe 's/\./,dc=/g&&s/^/dc=/g' dc=site,dc=company,dc=com

regex perl

No comments:

Post a Comment