java - RegEx to match a string between a set of words -


I am trying to match the words of a word between two words in a string. I am using Java Regx.

Input Text

  The cunning fox jumping on the big dog and ran   

Expected output

  large   

RegEx used

  ( ? & lt; = (Fox [A-Z0-9] *)) (? s) (. *?) (? = \ sdog)   

I get output Which gives me all the words between fox and dog

"fox" Following the word one or more all upper case words In the pursuit of these two words, I need to match all the words until I receive "dog"

Also, in Capture Group 0 I Need to get the desired output. I can not use different capture groups. This is a limit to my application.

Any help on this is greatly appreciated.

You can use this regex:

  ^. * Fox [A-Z0- 9 \ s] * (. *) Dogs * $   

To use in other cases you can pass fox and dog to your function.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -