Jeff wrote:
> I always have trouble with javascript regexes...
> I want to parse apart a string and remember the matches and use them
> elswhere.
> Say I have:
> var test_string='one_two-three';
> In perl I would do this;
> if($test_string=~/(.*)_(.*)-(.*)/){
> print $2;
> }
> I'm not sure how to do this in javascript. Does $1 only work in the
> replace function????
Um... I suck at Regular Expressions (always have). But maybe:
http://www.hunlock.com/blogs/An_Introduction_to_Regular_Expressions_i...
http://www.regular-expressions.info/javascript.html
http://devedge-temp.mozilla.org/library/manuals/2000/javascript/1.5/g...
http://www.evolt.org/node/36435
...can be of some assistance. Otherwise, just wait, someone will be
alone momentarily with your regexp.
Ah what the hell... I'll throw up a regular expression (which is sure to
be corrected/flawed):
var test_string = 'one_two-three';
var _regexp = /(\w+)_(\w+)-(\w+)/;
alert(test_string.replace(_regexp, '$2'))
That is basically the exact same thing you have. I am sure regexp gurus
can offer a better solution though, both in your example and mine.
--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.