I have been trying to write regular expression for very simple string but have not been able to do so:
x = "abc 10 def price 100 ghi"
I tried regex:
"(\\w\\s)+(price)(\\s\\w)+"
String regex = "(\\w\\s)+(price)(\\s\\w)+";
String test = "abc 10 def price 100 ghi";
System.out.println(test.matches(regex));
It returns false.
This regex should match with the String above, however in my case regex is not matching the string.
Any help is highly appreciated.
The basic requirement is that any number of words/digits can come before "price" and any number of words/digits can come after "price". Although there should be space before and after price and there should be atleast one word before price and atleast one word after price. for example all of below string are acceptable:
abc 10de price xyz
abc 10de price 1000 xyz
abc 10 de price 1000 xyz
abc 10 de de price 1000 xyz
\wmatches a word character. Not a word..*matches string above too ;-)