0

I'm trying to use regex group into a Java regex.

Regex

boolean res = (frequency.matches("\\[((DAY (3[01]|[12][0-9]|[1-9]))|(EVERY DAY)|(EVERY (MONDAY|TUESDAY|WEDNESDAY|THURSDAY|FRIDAY|SATURDAY|SUNDAY))|(ONLY MONTH (JANUARY|FEBRUARY|MARCH|APRIL|MAY|JUNE|JULY|AUGUST|SEPTEMBER|OCTOBER|NOVEMBER|DECEMBER) \\[((?2)|(?4)|(?5))+( ; ((?2)|(?4)|(?5)))*\\]))+( ; (?1))*\\]"))

Some results examples

[EVERY MONDAY] -> true
[DAY 1 ; EVERY FRIDAY] -> true
[EVERY MONDA] -> false
[DAY 32] -> false
[EVERY DAY ; EVERY SUNAY -> false
[MONTH JUNE [EVERY DAY]] -> true
[MONTH MAY [EVERY WEDNESDAY] ; MONTH JUNE [EVERY FRIDY]] -> false
[MONTH MAY [EVERY WEDNESDAY] ; MONTH JUNE [EVERY FRIDAY]] -> true

Error

java.util.regex.PatternSyntaxException: Unknown inline modifier near index 217

Already try

I saw this post however I don't understand how it works and how to solve my problem with the accepted answer.

Thanks in advance for help.

Royce
  • 1,557
  • 5
  • 19
  • 44
  • I use https://regex101.com/ to test my regexpressions. – Adder Aug 23 '19 at 11:26
  • Yes me too. This is working on regex101 but not with Java. regex101 don't have an option for writing Java regexes. – Royce Aug 23 '19 at 11:28
  • 3
    `(?1)` and the other recursive matchings are not supported in Java. The problem in your question is already reproducible using `(a*)(?1)` as regex. See [here](https://stackoverflow.com/a/8660012/6707985). You can try to build a bigger regex that matches sections and then iterate over the sections to match them to a bigger regex that checks the values. – geisterfurz007 Aug 23 '19 at 11:49
  • Oh thanks a lot. So to fix it I replaced all group call by the value. – Royce Aug 23 '19 at 12:29

0 Answers0