|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
Regular expression
Look at this code...
================================================== ============================= string strClaim = "BER"; Regex objNaturalPattern = new Regex("[Bb][Ee][Rr]|[Tt][Ww][Oo]|[Ss][Tt][Oo]"); objNaturalPattern.IsMatch(strClaim); ================================================== ============================= ok the return value to "objNaturalPattern.IsMatch(strClaim);" will be true as it matches [Bb][Ee][Rr]. Now what I might want to do and it needn't only apply to this example is know which Regular expression ([Bb][Ee][Rr]|[Tt][Ww][Oo]|[Ss][Tt][Oo])the string matched. Is there any possible way to get some kinda of return value to say which one was matched? as in a string matching [Bb][Ee][Rr] would return 0 as in a string matching [Tt][Ww][Oo] would return 1 as in a string matching [Ss][Tt][Oo] would return 2 no match could return -1 Is this posible? Is there a method that I have over looked? elp! |
|
#2
|
|||
|
|||
|
Why not just use three separate regexps?
Hadley |
|
#3
|
|||
|
|||
|
Javascript?
Why use regexp here? It would appear that you could convert the string to be matched to lower case and simply use a switch() case statement to return the correct value: Code:
foobar = foo.toLowerCase();
switch (foobar) {
case "ber":
return 0;
break
case "two":
return 1;
break
case "sto":
return 2;
break
default:
return -1;
}
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Regular expression |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|