javascript - regex: read character behind number -


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" -> und 

but if type:

 str= "kw-tc800h2und ->  result tc-800h2und.  //it makes script read t in front of 800  want result und  

how make code check @ character behind 800?

edit

after code 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, can show result if:

str= "kw-tc800un2d"  want result -> un2d 

try this:

 var patt1 = /(t|ee|eju)\d*$/i; 

it match sequence of non-digit characters starting t, ee or eju, , finishing @ end of string. if string has end d in examples, can add in:

 var patt1 = /(t|ee|eju)\d*d$/i; 

if want match anywhere, not @ end of string, try this:

 var patt1 = /(t|ee|eju)\d*d/i; 

edit: oops! no, of course doesn't work. tried guess meant [t|ee|eju], because it's character class matches one of characters e, j, t, u or | (equivalent [ejtu|]), , sure couldn't meant. heck, try this:

 var patt1 = /[ejtu|]\d*d/i; 

i still don't understand you're trying do, trial , error way move ahead. @ least tested time! :p

edit: okay, match can contain digits, can't start one. try this:

var patt1 = /[ejtu|]\w*d/i; 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -