Sorry if this is a dupe, I did search but couldn't seem to find something that matched my query.
I have a replacer function in java that runs multiple regexes to find and replace specific strings.
One of them is looking at numbers, and if it finds a number it adds space around it, for example;
test123 > test 123
regex used is "(([0-9]+)" and it replaces it with " $1 "
I have hit an issue now though that in a few edge cases I need to not split the number from a specific string, like hash names for example. So I now need to update my regex to wrap any combination of numbers with spaces, UNLESS it matches a specific sequence.
For example, I want the following results;
- test123 > test 123
- 84test > 84 test
- test md5 > test md5
- sha256 > sha256
- word two sha1 > word two sha1
- w0rd > w 0 rd
- aisha256 > aisha 256
- word md 5 > word md 5 etc
I've tried using negative lookbehind to match the words like md5, sha1, sha256, etc but it still seems to split the numbers. I'm sure its something simple I am doing wrong.... "((?!md5)(\d+))"
So basic rules are, any digit found in the string should be surrounded by spaces UNLESS it is preceeded by the word sha or md. If there is whitespace already between the number and md or sha, the whitespace should remain. sha or md could be the start of the string OR be preceeded by whitespace or an. underscore, but cannot be the end of a longer word or in the middle of a word.
Thanks