xelawho
06-22-2012, 06:51 AM
hello,
apparently javascript doesn't allow this:
/(?<=\d).*/
(I get an invalid group error)
but all I want is to replace everything after the first number, not including the number. I just can't seem to get my head around regex. Any hints?
Philip M
06-22-2012, 07:39 AM
var str= "abc123xyz";
str = str.replace(/(.*?\d+).*/i, "$1");
alert (str);
The new radio telescope will be the biggest in history, and will enable huge strides in gastronomy. - Reporter BBC Radio 1
xelawho
06-22-2012, 12:41 PM
thanks, Philip. It's not exactly what I had in mind, though - using your example, say I wanted to replace the xyz (although xyz changes) with def. I could do:
str = str.replace(/(.*?\d+).*/i, "$1")+"def"
but isn't there some funkier way of doing it?
Philip M
06-22-2012, 01:28 PM
<script type = "text/javascript">
var str= "abc123xyz";
str = str.replace(/(.*?\d+).*/i, "$1def");
alert (str);
</script>
Not sure how to make this "funkier".
xelawho
06-22-2012, 02:00 PM
that's funky enough, thanks :thumbsup: