i have regex code:
<script type="text/javascript">
var str = "kw-xr55und";
var patt1 = /[T|EE|EJU].*D/i;
document.write(str.match(patt1));
</script>
it can read:
str= "KD-R55UND" -> as UND
but if i type:
str= "kw-tc800h2und -> result tc-800h2und. //it makes script read T in front of 800
i want the result as UND
how to make the code just check at character behind the 800?
EDIT
After this code it can work:
<script type="text/javascript">
var str = "kw-tc800h2und";
var patt1 = /[EJTUG|]\D*D/i;
document.write(str.match(patt1));
</script>
but show next problem, i can show the result if:
str= "kw-tc800un2d"
i want result like -> UN2D
Try this:
It will match a sequence of non-digit characters starting with
T,EEorEJU, and finishing at the end of the string. If the string has to end withDas in your examples, you can add that in:If you want to match it anywhere, not just at the end of the string, try this:
EDIT: Oops! No, of course that doesn’t work. I tried to guess what you meant by
[T|EE|EJU], because it’s a character class that matches one of the charactersE,J,T,Uor|(equivalent to[EJTU|]), and I was sure that couldn’t be what you meant. But what the heck, try this:I still don’t understand what you’re trying to do, but sometimes trial and error is the only way to move ahead. At least I tested it this time! 😛
EDIT: Okay, so the match can contain digits, it just can’t start with one. Try this: