I have this requirement - for an input string like the one below
8This8 is &reallly& a
I would like to remove the matching word boundaries (where the matching pair is 8 or or%, etc.) and will result in the following
This is really a test of repl%acing %mul%tiple matched 9pairs
This list of characters, which is used for pairs, may vary, for example. 8.9,%, #, etc., And only those words corresponding to the beginning and end of each type will be deprived of these characters, with the same character embedded in the remaining word, where it is.
Using Java, I can make a pattern like \\b8([^\\s]*)8\\b and replace as $ 1 to capture and replace all occurrences of 8 ... 8, but how to do this for all types of pairs?
I can provide a template such as \\b8([^\\s]*)8\\b|\\b9([^\\s]*)9\\b .. etc. which will match all types of matching pairs * 8.9, ..), but how to specify the substitution group 'variable' -
eg. if the match is 9 ... 9, the replacement should be equal to $ 2.
I can, of course, run it through several of them, each of which replaces a certain type of pair, but I wonder if there is a more elegant way.
Or is there a completely different way to approach this problem?
Thanks.
java regex
ssen
source share