Sublime Forum

Regex lookbehind with options

#1

013:06:10.674 WARNING baseclass::method some event happening
013:06:10.702 INFO derivedclass::method1 too much of log
013:06:10.703 ERROR devclass::subclass::methodb this is the actual functionality
013:06:10.703 ERROR devclassb::subclassb::method1 after the crash

in the above i want to select strings with

scope operator (::)

which comes after WARNING INFO ERROR how to select with regex

i tried like below,
(\d\d\d:\d\d:\d\d.\d\d\d INFO|ERROR|WARNING )(\w+::\w+) but it only selects warning. i tried to find using regex find

0 Likes

#2
(\d\d\d:\d\d:\d\d.\d\d\d (INFO|ERROR|WARNING) )(\w+::\w+)
                         ^                  ^
1 Like

#3

Thanks that was very helpful.

but one last thing… what if i need to select the expression

(\w+::\w+) and not the whole string…

0 Likes

#4

So, why not just select with (\w+::\w+)? Will it be overkilling? (except that it doesn’t fully match your given test case. \w+(::\w+)+ does.)

1 Like

#5

there are many other places where class::function is present, so i want to select the string which is just after the LOG, WARNING, or ERROR.

i am interested to extract strings which are functions responsible for printing the log, and not the methods or classes mentioned in the detail part of the string.

Also i heard that lookbehind or someother tool would help this. But im not clear about it.

0 Likes

#6

Lookahead only supports fixed-width patterns, so

((?<=\d\d\d:\d\d:\d\d.\d\d\d ERROR )|(?<=\d\d\d:\d\d:\d\d.\d\d\d WARNING ))\w+(::\w+)+

should work for ERROR|WARNING case for example.


For command line solution,

grep -P '^\d+:\d+:\d+.\d+ (ERROR|WARNING)' MY_LOG_FILE.log | awk '{ print $3 }'
1 Like

#7

((?<=\d+:\d+:\d+.\d+ ERROR )|(?<=\d+:\d+:\d+.\d+ WARNING ))\w+(::\w+)+

i tried to paste in the search window and it is not working… am i missing some process ?

I have enabled the regex in the find also

0 Likes

#8

update. I forget the “fixed-width” :slight_smile:

0 Likes

#10

Thanks jfcherng …it is working… Yes.

0 Likes

#11

so fixed width is like not with + sign. hope i understood properly

0 Likes