0

I have this text:

System.FormatException: String '' was not recognized as a valid DateTime. at Application.Mappers.AutoMapperProfile.<>c.<.ctor>b__0_92(CartCampaignDto x, CartCampaign y) in /build/src/Application/Mappers/AutoMapperProfile.cs:line 60 at lambda_method543(Closure , Object , Cart , ResolutionContext ) --- End of inner exception stack trace --- at lambda_method543(Closure , Object , Cart , ResolutionContext ) --- End of inner exception stack trace --- 

I'm trying to match only this part

System.FormatException: String '' was not recognized as a valid DateTime.

I tried

^(.*) at.*)

^(.+)(?=at ){1}(.*)

but it didn't work.

EDIT:

This is not in any programming language, this is to build a NewRelic dashboard where you can add a Regex to get some insights.

EDIT 2 NewRelic uses Google/R2 Regex

EDIT 3 I'm trying to build this query

SELECT uniqueCount(1) From Log where `@l` = 'Error' FACET capture(`@x`, r'(?P<anyvarname>^(.*?\.)\s*at\b)')

EDIT 4 Not sure why this doesn't work

enter image description here

Nour
  • 5,252
  • 3
  • 41
  • 66

2 Answers2

1

I think this will work for your:

^.+\.\s

Quickly breaking it in pieces:

  • ^.+ -> matches, from the beggining of the line, any 1 or more characters
  • \.\s -> matches a dot followed by a whitespace.

testing the regex

LeYAUable
  • 1,613
  • 2
  • 15
  • 30
  • This works in a normal text, but it turned out that NewRelic uses Re2, so didn't work the same for some reason. – Nour Aug 23 '22 at 14:39
  • @Nour This pattern is RE2 compliant. – Wiktor Stribiżew Aug 23 '22 at 14:40
  • @LeYAUable I'm putting the same expression in a named group as required by NewRelic `r'(?P^(.*?\.)\s*at\b)` does that change anything? – Nour Aug 23 '22 at 15:05
  • I guess you then need to get the captured instead of just the capture of the entire regex. I don't have experience with NewRelic but Wiktor said that the pattern is compliant. – LeYAUable Aug 23 '22 at 15:12
  • typo above, should be "...get the captured group instead..." – LeYAUable Aug 23 '22 at 15:42
0

You could write the pattern matching the whole line with a named capture group:

(?P<anyvarname>(.*?\.)\s*at\b).*

See these pages for more information about capture

The fourth bird
  • 154,723
  • 16
  • 55
  • 70