I only want to replace words in a string, if there is no word character (\w)
or hyphen before or after the word.
Text:
#button .button large-button tinybutton size9button #9button button-large buttontiny
Exptected result after replacement:
#text .text large-button tinybutton size9button #9button button-large buttontiny
Regular Expression:
(?<![\w-])(button)(?![\w-])
- The regular expression currently only matches the first occurrence (button after
#
). What do I need to do to match all occurrences? - How can I replace
button
withtext
or any other word in Java?
I have read the topic Can I replace groups in Java regex?, but I really do not understand how to use the example code for my special case. Unfortunately I haven't got any code to show. :/