in reply to split string using regex

I think an easy approach would just be to replace those spaces in the datetime stamps with another character, then parse the fields, then you can go back in and replace the spaces if needed. For example,
use Data::Dumper; my $inp = 'AAA * BBB CCC * * "2000 01 00 00 00" "2004 01 00 00 00"'; $inp =~ s/(\d) (\d)/$1-$2/g; my @fields = split /\s+/, $inp; print Dumper(\@fields);
Which outputs
$VAR1 = [ 'AAA', '*', 'BBB', 'CCC', '*', '*', '"2000-01-00-00-00"', '"2004-01-00-00-00"' ];
However, this assumes that the other fields don't start/end with a number. I'm only going off your example above.

---
echo S 1 [ Y V U | perl -ane 'print reverse map { $_ = chr(ord($_)-1) } @F;'
Warning: Any code posted by tuxz0r is untested, unless otherwise stated, and is used at your own risk.

Replies are listed 'Best First'.
Re^2: split string using regex
by Anonymous Monk on Jun 25, 2013 at 06:20 UTC
    I have below log line,

    <190>date=2005-05-25 time=07:17:21 device_id=FGT1002104201869 log_id=0316096002 type=webfilter subtype=urlexempt pri=information vd=root user=bpdcad\schiavok src=192.168.3.70 sport=3557 dst=207.68.177.125 dport=80 service=http hostname=h.msn.com url=/c.gif?RF=http%3a%2f%2fby101fd%2ebay101%2ehotmail%2emsn%2ecom%2fcgi%2dbin%2fHoTMaiL&PI=44364&DI=7474&PS=74565 status=allow msg="URL is allowed because it is in URL exempt-list"

    I want to split the above line with space and store into an array, but dont want to split if content is in between "" quotes say msg="URL is allowed because it is in URL exempt-list" i want above content as single content and should not divide the content under " quotes as separately. any help would be appreciated... Thanx. jai...

      Try this:

      while( $line =~ /(\w+)=("[^"]+"|\S+)/g ) { print "$1: $2\n"; }

      Warning: no guarantees if your string is not well-formed.