in reply to Steps to get a substring from a string
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 Deltronics
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Steps to get a substring from a string
by Not_a_Number (Prior) on Jul 21, 2015 at 17:34 UTC | |
by CountZero (Bishop) on Jul 21, 2015 at 17:45 UTC | |
|
Re^2: Steps to get a substring from a string
by shroh (Acolyte) on Jul 21, 2015 at 23:21 UTC | |
by AnomalousMonk (Archbishop) on Jul 22, 2015 at 01:55 UTC | |
by CountZero (Bishop) on Jul 22, 2015 at 06:38 UTC | |
by Anonymous Monk on Jul 22, 2015 at 00:03 UTC |