I am writing a regex to match the string containing more than 2 words and should have at least 1 digit available or 1 word with no digits.
i.e If I have following strings:
1. "Sample data with no digit" (no digit)
2. "1004" (less than 2 words)
3. "1004 1008" (no alphabets)
4. "1004 data" (exactly 2 words)
5. "5ample Data with digits" (note that S-> 5)
6. "Sample Data with 1004"
The regex should match the 5th,6th strings (reason for not fetching others is mentioned along with the data)
I tried following but the following always returns all the strings:
[\d[0-9]|[ABEGFIHKJLOQPSRUTXZbgfihkjloqpsuz!]]+[\w\s]* (returns all strings)
Please note that I am using JAVA.
Please help and thanks in advance.
([0-9]|[a-zA-Z]){2,}\s*
– Lino