regex - Regular Expression for Searching Duplicate Word in java -
i want find repeating word given string. want have regular expression find every occurrence of word. example "i want eat apple. apple fruit".
the regular expression should find out word "apple".
you can use following match duplicate words in line.
(\\b\\w+\\b)(?=.*\\b\\1\\b) // matches duplicates in single line edit: if want match duplicates in multiple lines can use:
(\\b\\w+\\b)(?=[\\s\\s]*\\b\\1\\b) // or above regex dotall flag
Comments
Post a Comment