-2

Why isn't the following

([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}) (\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2},\d{3}) \[(.*?)\] ([^ ]*) +([^ ]*) - (.*)$

not matching any thing from the following

22bd49ad-eff4-4d20-b87d-eae1d0ab90e6 2015-12-28 13:28:19,025 [http-nio-8090-exec-3] DEBUG o.s.b.a.e.mvc.EndpointHandlerMapping apps : Did not find handler method for [/facets/apps/search]

EDIT: posting the correct link

Test linK https://regex101.com/r/lV4wU2/1

Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327

2 Answers2

2

You can use this regex:

^[a-fA-F0-9]{8}(?:-[a-fA-F0-9]{4}){4}[a-fA-F0-9]{8} (\d{4}(?:-\d{2}){2}) ((?:\d{2}:){2}\d{2},\d{3}) \[(.*?)\] (\S*) +(\S*) [^:]*: (.*?)(?=\n[a-fA-F0-9]{8}|\z)

RegEx Demo

[^ ]* can be replaced by \S* in your regex and last part doesn't have hyphen.

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • perfect. is it also possible to match the exception stacktraces like below https://regex101.com/r/lV4wU2/4 – Aravind Yarram Jan 01 '16 at 17:32
  • Can be **shortened**: `-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}` **==>** `(?:-[a-fA-F0-9]{4}){4}[a-fA-F0-9]{8}` [**Demo**](https://regex101.com/r/lV4wU2/6) – Tushar Jan 01 '16 at 17:36
  • [ok try this regexc to capture multiline exception trace](https://regex101.com/r/lV4wU2/5) – anubhava Jan 01 '16 at 17:37
  • 1
    Or `^[a-fA-F0-9]{8}(?:-[a-fA-F0-9]{4}){4}[a-fA-F0-9]{8} (\d{4}(?:-\d{2})) (\d{2}(?::\d{2}){2},\d{3}) \[(.*?)\] (\S*) +(\S*) (.*)$` – Tushar Jan 01 '16 at 17:39
  • Yes Tushar, thanks for the tip. I have included that in recent edit. – anubhava Jan 01 '16 at 17:40
  • 1
    Thanks it is reduced further. – anubhava Jan 01 '16 at 17:53
  • is there a way to make this work in java/scala? seems like there are difference – Aravind Yarram Jan 01 '16 at 18:55
  • This should work fine in Java. Just use **`String regex = "(?ms)^[a-fA-F0-9]{8}(?:-[a-fA-F0-9]{4}){4}[a-fA-F0-9]{8} (\\d{4}(?:-\\d{2}){2}) ((?:\\d{2}:){2}\\d{2},\\d{3}) \\[(.*?)\\] (\\S*) +(\\S*) [^:]*: (.*?)(?=\n[a-fA-F0-9]{8}|\\z)"`** – anubhava Jan 02 '16 at 04:29
1

The ending part +([^ ]*) - (.*) doesn't match with

o.s.b.a.e.mvc.EndpointHandlerMapping apps : Did not find handler method for [/facets/apps/search]

so the entire expression doesn't match.

EDIT You should try something like that to match your input : [a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12} (\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2},\d{3}) \[(.*?)\] ([^ ]*) ([^ ]*) (.*)$

Prim
  • 2,880
  • 2
  • 15
  • 29