Change
12-16-23-some-words-now
to
12/16/23/some-words-now
thanks!! Your help is much appreciated.
If the characters between the first three dashes are always numbers, you can do it like this:
variable = variable.replace(/^(\d+)-(\d+)-(\d+)-/, "$1/$2/$3/");
If they could be any arbitrary characters, then you can do it like this:
variable = variable.replace(/^([^-]+)-([^-]+)-([^-]+)-/, "$1/$2/$3/");
Working demo: http://jsfiddle.net/jfriend00/YySFh/
This should do the trick:
'12-16-23-some-words-now'.replace(/^(\d+)-(\d+)-(\d+)-/g, '$1/$2/$3/');
Are the first three always numbers?
^ operator.Find:
^([^-]*)-([^-]*)-([^-]*)-(.*)
Replace:
$1/$2/$3/$4
[^-]* is more precise and faster than .*?). Say what you mean - mean what you say! +1