- Joined
- Sep 10, 2012
- Messages
- 284
- Likes received
- 35
- Thanks received
- 9
- Location
- UK - South West
The ^.* matches preceding garbage. For the trailing garbage the $ would be .*$ however both are redundant to your purpose and can be omitted.
The (.+) matches to end of line and not just the desired string and the () are redundant in that context anyway. Probably you want to match for a string bounded by quotes and not itself including quote char, e.g. "[^"]*"
Add a leading (^| ) if matching on othersrccountry="..." would be bothersome.
In the shell, 'single quotes' saves from having to use backslash escapes.
Code:$ cat test.dat date=2016-11-26 time=17:03:26 devname=XXXXX3X15013159 devid=XXXXX3X15013159 logid=0001000014 type=traffic subtype=local level=notice vd=root srcip=xx.xx.xx.xx srcport=4927 srcintf="wan" dstip=xxx.xxx.xxx.170 dstport=23 dstintf="root" sessionid=2417401 proto=6 action=deny policyid=0 policytype=local-in-policy dstcountry="United Kingdom" srccountry="United Kingdom" trandisp=noop service="TELNET" app="Console Management(Telnet)" duration=0 sentbyte=0 rcvdbyte=0 sentpkt=0 appcat="unscanned" crscore=30 craction=131072 crlevel=critical $ grep -Eo "srccountry=\"[^\"]*\"" test.dat srccountry="United Kingdom" $ grep -Eo 'srccountry="[^"]*"' test.dat srccountry="United Kingdom"
I don't think the brackets are redundant.
In a true regex they would return the first match group.
Which in the OPs case should be "United Kingdom".
I would recommend www.debuggex.com for visual inspection of the regex. Helps a lot when trying to visualise it.

