javascript regex to replace space with a hyphen -


i need regex should read string :

  1. with 1 unlimited numbers (say upto 10)
  2. read space in between
  3. 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

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -