Rites
Rites

Reputation: 2332

Need a regex using java

    **************************
    * Ending Case(test) *
    **************************
SET: Global["test_status"]=FAILED
=========================
= Ending Test (test) =
=========================

Regex which will return the status i.e. FAILED or PASSED from the above text.

Currently I'm using

.*SET: Global\\W"test_status"\\W=(.*)

But it returns

FAILED
=========================
= Ending Test (test) =
=========================

Thanks in advance

Upvotes: 0

Views: 262

Answers (4)

Don Mackenzie
Don Mackenzie

Reputation: 7963

You could use:

"(?m)=(\\w+)\\b"

as the argument to Pattern.compile()

You don't need much context in this example. The pattern is just the multi-line flag (?m) followed by an '=' character as context and a capturing group (\\w+) delimited by a word boundary marker \\b

Use the find() method on the Matcher and extract group 1.

Upvotes: 0

cdhowie
cdhowie

Reputation: 169018

Try this one:

^SET: Global\["test_status"\]=(.*)$

Represented as a Java string:

"^SET: Global\\[\"test_status\"\\]=(.*)$"

EDIT: This pattern should be used with Pattern.MULTILINE, but not Pattern.DOTALL.

Upvotes: 1

Rites
Rites

Reputation: 2332

Finally it worked

.*SET: Global\\[\"test_status\"\\]=(.*)\\r\\n=.*\\r\\n= Ending .*

Upvotes: 0

Kelly S. French
Kelly S. French

Reputation: 12334

One problem with using .* is it doesn't stop at the end of the line. Try something like this:

^SET: Global\["test_status"\]=(.*)$ 

Upvotes: 0

Related Questions