I have a long String and this is an example of it :
I want to delete all dashes like the second dash here (dashes that have text before & after them, but not space characters like the first dash). Doing this in regular expressions would be great, so i want to say :
"Find any dashes that have text before and after them(but no spaces) and if found then delete that dashes from the text".
Hesham Gneady wrote:I want to delete all dashes like the second dash here (dashes that have text before & after them, but not space characters like the first dash). Doing this in regular expressions would be great, so i want to say :
"Find any dashes that have text before and after them(but no spaces) and if found then delete that dashes from the text".
Sure. Regular expressions can do this with absolutely no difficulty whatsoever. What have you tried so far?
I know how to find the text using regular expressions, but i need a method in java to remove the dash from the found text.
For the example i wrote above, here is the regex that will grab the text "between-text" :
You can use the replaceAll() method to change the matched text -- in this case, change the dash to something else, such as a space. As for not deleting whats around the dash, you can change those components of the match to either a look-ahead or look-behind.