cipher has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I am new to perl, I am stuck on regex part of parsing a file, help would be appreciated.
I am parsing a log file which has log entries per line.
I am loading regex match in a scalar.
I am trying to match this data:
some_fields msg="http_decoder: HTTP.Unknown.Tunnelling" some_fields
This message keeps on changing.
Here is my regex:
I also tried adding the global match /g still does not work. Any clue? I tried several combinations it does not work. If I use the regex:
if ($message =~ /^msg/) - It only gives me msg="http_decoder: as output
I want the entire string
msg="http_decoder: HTTP.Unknown.Tunnelling"
I also tried
(/^msg=\"(.*?)\"+) This also gives me msg="http_decoder:
I am trying to match this data:
some_fields msg="http_decoder: HTTP.Unknown.Tunnelling" some_fields
This message keeps on changing.
Here is my regex:
Here is my script:/msg=\"+((?:([^:,]+):\s|)([^,]+?)\s*(?:\s*,.*?|)))\"+/
I tried online regex tools and this matches the string but when using perl it does not show any result.foreach $message (@logs) { if ($message =~ /msg=\"+((?:([^:,]+):\s|)([^,]+?)\s*(?:\s*,.*?|))\"+/) + { print $message"\n"; } }
I also tried adding the global match /g still does not work. Any clue? I tried several combinations it does not work. If I use the regex:
if ($message =~ /^msg/) - It only gives me msg="http_decoder: as output
I want the entire string
msg="http_decoder: HTTP.Unknown.Tunnelling"
I also tried
(/^msg=\"(.*?)\"+) This also gives me msg="http_decoder:
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Perl Regex
by ikegami (Patriarch) on Nov 23, 2010 at 06:36 UTC | |
Re: Perl Regex
by chrestomanci (Priest) on Nov 23, 2010 at 09:48 UTC | |
by cipher (Acolyte) on Nov 23, 2010 at 10:36 UTC | |
by afoken (Chancellor) on Nov 23, 2010 at 11:03 UTC | |
by cipher (Acolyte) on Nov 23, 2010 at 11:12 UTC | |
by cipher (Acolyte) on Nov 23, 2010 at 11:53 UTC | |
| |
Re: Perl Regex
by samarzone (Pilgrim) on Nov 23, 2010 at 07:44 UTC | |
Re: Perl Regex
by umasuresh (Hermit) on Nov 23, 2010 at 18:18 UTC | |
by cipher (Acolyte) on Nov 23, 2010 at 23:45 UTC |
Back to
Seekers of Perl Wisdom