I’m new to regular expressions and I need to find a regular expression that matches one or more digits [1-9] only ONE ‘|’ sign, one or more ‘*’ sign and zero or more ‘,’ sign.
The string should not contain any other characters.
This is what I have:
if(this.ruleString.matches("^[1-9|*,]*$"))
{
return true;
}
Is it correct?
Thanks,
Vinay
I think you should test separately for every type of symbols rather than write complex expression.
First, test that you don’t have invalid symbols –
"^[0-9|*,]$"Then test for digits
"[1-9]", it should match at least one.Then test for
"\\|","\\*"and"\\,"and check the number of matches.If all test are passed then your string is valid.