javascript regex to replace space with a hyphen -
i need regex should read string :
- with 1 unlimited numbers (say upto 10)
- read space in between
- with 1 unliimited numbers (say upto 10)
then replace space in string '-'
for ex: 123 456 should replaced 123-456.
there no other characters apart numbers in string.
var str = 'shop u5, 124 134 millers road'; var regex = /(.*\d{1,10})\s(\d{1,10}.*)/; if (str.match(regex)) { str = str.replace(regex, "$1" + "-" + "$2"); } alert(str)
output:
'shop u5, 124-134 millers road'
Comments
Post a Comment