i have this code:
<script type="text/javascript">
var str="KD-R35H2UND";
var patt1=/[G|T|EE|EJU].*D/i;
document.write(str.match(patt1));
</script>
by using code at var patt1=... i can show like this:
if i type KD-R35ED => SHOW ED
KD-R35UND => UND
KD-R35JD => JD
KD-R35TJD => TJD
KD-R35EED=> EED
my problem is: if i type KD-R35GD it can show GD but if KD-R35D it can’t show anything..how to make it works?
b*means “match zero or more occurences ofb“..means “match any character except newline”.[EE|EJU]means “match anE, a|, aJor aU“..*means “match any character except newline zero or more times”.Dmeans “match aD“.So the regex is doing what you asked it to do.
From the examples you provided in your question, I’m guessing that the actual rules should be:
KD-R35.E, aJor aUamong them, andD.These rules, as a regex, read:
or, in JavaScript:
I’m assuming that upper/lowercase don’t matter.
EDIT: Erm, your new edit changes the rules. It seems that any string is allowed as long as it starts with
KD-R35and ends inD. In this case, the regex would simply be/^KD-R35(\w*D)$/i.