-1

Hello I have a string I would like to regex. The pattern is

{statusCode="200"} 711.689923094129 1541361264000

I want to strip out everything and only have the actual status code so 200

"(.*?)"

I would have thought this would work but I am not seeing any results.

Any advise?

Luke Toss
  • 356
  • 3
  • 18

1 Answers1

-1

Not sure how you are "matching" your regex to the string, but if you are using java or c# native libraries, then by default the regex has to match the WHOLE input string.

For example with java...

Pattern.matches("a", "bab"); //False
Pattern.matches(".*a.*", "bab"); //True

"(.*?)" would not match input string {statusCode="200"} 711.689923094129 1541361264000. It would actually fail after the first character check because the input string does not start with " but the regex says it must.

So you would have to revise your regex to match the ENTIRE input string.

If you know the input string is ALWAYS going to have the same format, then use it to your advantage. I suggest using this regex. {statusCode=(".*?").*

if you are confident there are always only going to be 2 double quotes in this input string, then i guess you could get away with .*"(.*?)".* (don't think the ? is necessary since you know there's only 2 quotes).

shockawave123
  • 648
  • 4
  • 15