Tuesday, 15 January 2013

javascript - Regex to remove string after last number? -


There are so many regexs but I could not find a solution to my specific problem.

Look at these stars:

  My road 13a mystreet 3 B My street colosse 15a  

How do I make those people Can return:

 <13> matches with "13A, 13A" and  \ "\"  My street 13 mystreet 3 My road karlos 15  

\ d + [az, az] D + [az, az] it matches white spots, then I use it: / P>

  myCutStr = myOriginalString.match (/ \ d + [az, a-za] / g); MyNewStr = myCutStr.replace (/ [^ \ d] / g, ''); MyOriginalString.replace (myCutStr, myNewStr);  

But can I add \ d + [a-z, A-Z] in any way and ignore white spaces in that regEx? So that it will also match with one of the white areas of my \ d + [az, az] ?

The place of one place would be enough, that is, all the non-digit characters with all empty strings place.

  string.replace (/ \ D + $ / g, '');  

OR

  string.replace (/ (\ d) \ D + $ / g, '$ 1');  


No comments:

Post a Comment