**************************
* 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
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
.
One problem with using .* is it doesn't stop at the end of the line. Try something like this:
^SET: Global\["test_status"\]=(.*)$
Finally it worked
.*SET: Global\\[\"test_status\"\\]=(.*)\\r\\n=.*\\r\\n= Ending .*
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.
精彩评论