in reply to Re: split string using regex
in thread split string using regex

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...

Replies are listed 'Best First'.
Re^3: split string using regex
by hdb (Monsignor) on Jun 25, 2013 at 07:03 UTC

    Try this:

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

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