I am learning regex (with this site) and trying to figure out how to parse the following string 1***2 to give me [1,2] (without using a specific case for 3 asterisk). There can be any number of asterisks that I need to split as one delimiter, so I am looking for the * char followed by the * wildcard. The delimiters could be letters as well.
The output should only only be numbers so I use ^-^0-9 to split by everything else.
So far I have tried:
input.split("[^-^0-9]"); // Gives me [1, , ,2]
input.split("[^-^0-9\\**]"); // Gives me [1***2]
input.split("[^-^0-9+\\**]"); // Gives me [1***2]
\* does not work as it is not recognized as a valid escape character.
Thanks!
You are looking for
This splits the string on one or more consecutive asterisks.
To allow other characters (e.g. letters) within delimiters, add them to the
[*]character class.