I need to look for java regex pattern that finds input string in the format of 1=1 where prefix of "=" should have same count of digits with the suffix. Also here both prefix & suffix values should be the same like 1=1, 11=11, 223=223. Values like 1=2, 3=22, 33=22 should not match the pattern
Can we have a general pattern to satisfy above rules.
It indicates a specific number, lists of numbers, or range (to infinity). A number indicates an exact number of occurrences. The coma is used to indicate multiple (when between numbers) or a range to infinity (when not followed by a number.
[] denotes a character class. () denotes a capturing group. [a-z0-9] -- One character that is in the range of a-z OR 0-9. (a-z0-9) -- Explicit capture of a-z0-9 .
+: one or more ( 1+ ), e.g., [0-9]+ matches one or more digits such as '123' , '000' . *: zero or more ( 0+ ), e.g., [0-9]* matches zero or more digits.
It indicates that the subpattern is a non-capture subpattern. That means whatever is matched in (?:\w+\s) , even though it's enclosed by () it won't appear in the list of matches, only (\w+) will.
Use a back reference:
(\d+)=\1\b
of course, in java you need to escape the back slashes:
"(\\d+)=\\1\\b"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With