Sunday 15 June 2014

regex - I need a Regular Expression to find whitespaces and replace with a dash? -



regex - I need a Regular Expression to find whitespaces and replace with a dash? -

i thought might work: ^['\s+', '-', "this should connected"\w\s]{1,}$

but wrong it. no of regex place dashes between words while @ same time not placing dashes in front end of first word or behind lastly word? and, have 1 word no dashes required.

the tool using www.import.io allows me turn website table of info or api in seconds – no coding required. uses regex , xapath help refine , reformat info captures.

i don't know www.import.io, in plain javascript

" test string ".replace(/(\w+)\s+(?=\w)/g, "$1-")

has result:

" this-is-my-test-string "

the regex replaces every whitespace characters dashes between words, not @ origin or end of string.

(to more precise replaces every grouping of word characters , whitespaces followed word character same word characters without whitespaces , dash instead.)

regex

No comments:

Post a Comment