December 11th, 2013

How to get around regex greediness

Fighting greediness in regular expressions is a pain in the ass. Period.

The following example will get everything after the JSESSIONID= in the access log up to the first space character

cat /var/log/httpd/access_log.2013-12-06.txt | egrep -o "JSESSIONID=[^[:space:]]*"