0

Here is my test sentence:

in setup or operation state, the blood warmer shall declare an urgent state if its liquid leakage sensor detects liquid leakage.

I want extract:

setup or operation

note that there maybe two or more state in the sentence,Just find the first one as the boundary.

I test my code in regex101: https://regex101.com/r/p18Hef/1

(in (.*) (state|mode|phase|states))

but it couldn't find the first state...

1 Answer 1

3

Regex is greedy by default. Your .* is matching all the way out to the next instance of "state", so you need to mark your .* as lazy with a ?.

The final regex is: (in (.*?) (state|mode|phase|states)).

More information can be seen at Regular expression operations.

Sign up to request clarification or add additional context in comments.

1 Comment

Maybe this is what he really wants? (?<=in ).*?(?=state|mode|phase|states)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.