I receive PatternSyntaxException when try to compile the following regex:
"bd".matches("(a)?b(?(1)c|d)")
this regex matches bd and abc. It does not match bc.
any ideas? thanks.
ok i need to write regex to match next 4 strings:
*date date* date date1*date2
should not match:
*date* date1*date2* *date1*date2 date** ...
but this should be done with single matching, not several.
please do not post answer like:
(date*date)|(*date)|(date*)|(date)
Adding a new answer based on the OP’s edit and samples:
ok i need to write regex to match next 4 strings:*date date* date date1*date2should not match:*date* date1*date2* *date1*date2 date** ...If I think I understand you, you could use a regex based on Alan Moore pseudo conditional trick.
Something like this
^(?:[*]())?date(?:(?!\1)[*](?:date)?|)$might work.I am asuming ‘date’ is the only text in the samples, and each group of non-space characters in the samples are distinct lines of text.
In your text that passes, there is only one form that requires a pseudo conditional. That is ‘date*date’. So, I’ve included a Perl sample below (since I don’t have a Java compiler) that expands the regex for clarity.
Output: