I need to know if a string matches several different criteria. I try to solve this using a regex and then see if it matches (in Java: str.matches (myRegex);), but I can't figure it out correctly.
The criteria are as follows:
- Corresponding line is constructed of 4 letters, [AZ]
- Perhaps it may precede (but not necessarily) one of the "-", "+" or "VC"
- It should match only strings containing exactly 4 letters (and possibly the preceding characters)
Examples:
- "SHSN" → match
- "+ SHRA" → match
- "VCSHRA" → match
- "CAVOK" → no match
- "- + SHSN" → no match
Can this be done in one regex? Or should it be done in code or in a combination of the two?
Thanks,
Linus
source share