I'm looking for a java regex that will return true if a string contains any char[including special char _(underscore) and -(hyphen)] more than 3 times.
example : Heloooo --->True hellooo --->Flase Heleoeoe---> False
got one \w{0,2}$ working fine for JS but not for JAVA Can anyone help, thanks in advance?
Asked
Active
Viewed 58 times
-1

Wiktor Stribiżew
- 607,720
- 39
- 448
- 563
-
1Perhaps this post can help you https://stackoverflow.com/questions/8880088/regular-expression-to-match-3-or-more-consecutive-sequential-characters-and-cons – The fourth bird May 20 '20 at 20:20
-
This question has been marked as a duplicate of a completely unrelated question. The one suggested by The fourth bird is actually what this question is a duplicate of. – user May 20 '20 at 23:38
1 Answers
0
Your JS regex doesn't seem right, but this (a|[^a])\1{3,}
should work.
Link to regex tester: https://regex101.com/r/MJjNhT/1

user
- 7,435
- 3
- 14
- 44
-
you can use this Platform https://www.freeformatter.com/java-regex-tester.html# for java regex101 uses JS. Unfortunately, this regex didn’t work for me but thanks. – sampad chakraborty May 21 '20 at 04:57
-
@sampadchakraborty Could you elaborate more on how it doesn't work? It seems to work for your test cases, at least. Perhaps I can help – user May 21 '20 at 15:42