Regex expression to return match if word is found at a particular distance from another word -


i need build regular expression return true or false specified word in same sentence either word "county" or "counties" , comes either before or after either of words , no more either 10 words or 100 characters apart "county" or "counties".

for example :

county test test1 test2 word test3 test4

or

test test1 test2 test3 word test4 test5 counties test6 test7

should return true, while

counties test1 test2 test3 test4 test5 test6 test7 test8 test9 test test8 test3 test4 word test5 test7

should return false

here got:

\bword\w+(?:\w+\w+){0,10}?counties\b 

i added county works far if words county and/or counties after word:

\bword\w+(?:\w+\w+){0,10}?(counties|county)\b 

can please point me in right direction?

does solve problem? tried on regex101

word\s\w*(?:(?!word)\w+\w*){0,10}?(?:counties|county)|(?:counties|county)\s\w*(?:\w+\w*){0,10}?word 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -