I am trying to find whether a pattern exists in a string.
Pattern I want to check is:
String starting with space or "#",
then with specific string "value1" followed by space or tab,
then "value2" and again space or tab,
ends with "value3".
Here a sample string to check:
String str = "# value1 values2 value3";
I tried the following regular expression, but it did't work:
str.matches("^\\s+#\\s+value1\\s+value2\\s+value3");
The above pattern always returns me false. Please help with regular expression.
Any help will be really appreciated.
#or aspace. But the string you posted starts with both: -# value1 values2 value3. It has both a#followed by a space.String str = "# value1 values2 value3"got an S in values2 and that's because your regex is not working? (apart of \\s#, use @RohitJain one)