You have the following four patterns of data:
If the above assumptions are correct, the following will do the trick:
Output:use Modern::Perl qw/2015/; while (<DATA>) { chomp; say "$_ => $1" if m/name=([^\.]+)/; } __DATA__ name=servername.xyz.abc.coom name=servername name=servername.xyz.com
update:name=servername.xyz.abc.coom => servername name=servername => servername name=servername.xyz.com => servername
To be fully compliant with the respective RFCs (see above), the regex should be m/name=([-0-9a-z]+)/i
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
My blog: Imperial DeltronicsIn reply to Re: Steps to get a substring from a string
by CountZero
in thread Steps to get a substring from a string
by shroh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |