Regex pattern matching issue

44 views Asked by At

Below is the text I am trying to match

3 INFO  ~ [com.Engine:164] italics

with

(?<=~\s\[)([a-zA-Z0-9\.]+)(?=:)(?<=:)(.*)(?=\])

I need to fetch 2 expressions out of it -

  1. com.Engine
  2. 164

and I do not need any more matches, not even the :.

(?<=~\s\[)([a-zA-Z0-9\.]+)(?=:)

is returning me com.Engine however the total regex doesn't give me any result.

Please help.

4

There are 4 answers

0
James Alarie On
I='3 INFO  ~ [com.Engine:164] italics';
J=I.replace(/^.*?\[(.*?)\].*$/,'$1').split(':');
alert(J[0]+'\n'+J[1]);
0
nu11p01n73R On

How about

(?<=~\s\[)([a-zA-Z0-9\.]+):[^]]+

Example : http://regex101.com/r/kT6vO6/1

  • :[^]]+ matches anything other than ] presceded by a :
0
vks On
(?<=\[)[^:]+|(?<=:)[^\]]+

Try this.See demo.

http://regex101.com/r/oE6jJ1/38

0
MBaas On

Not sure about the rules for the individual parts, but how about:

.*\[(.*):(\d*)\].*