-1

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

But something is wrong with it. Does anyone no of a regex that will place dashes between words while at the same time not placing dashes in front of the very first word or behind the very last word?

I also need to keep in mind that I don't want a dash before the first word or after the last word. And, sometimes I will only have one word so no dashes are required.

Jay Power
  • 11
  • 2
  • 4
    What language/tool are you using? – anubhava Oct 14 '14 at 19:14
  • So what should that thing at the first line be? In all languages I know regex look much different – msrd0 Oct 14 '14 at 19:14
  • possible duplicate of [Replace multiple whitespaces with single whitespace in JavaScript string](http://stackoverflow.com/questions/6163169/replace-multiple-whitespaces-with-single-whitespace-in-javascript-string) – vsync Oct 14 '14 at 19:23
  • Sorry guys new here and didn't expect to get comments so quickly. Apparently I have angered some people by seeming to ask the same question again but the truth of the matter is I have spent the last few days searching this site for a solution and have not found one so I posed the question here. As far as the language we are using, I am not sure but I did just pose that question to my support desk an should have an answer shortly. – Jay Power Oct 14 '14 at 19:40
  • I am still trying to get an answer to the question what language am I using. The tool I am using is www.import.io which allows me turn any website into a table of data or an API in seconds – no coding required. It uses regex and xapath to help refine and reformat the data it captures. – Jay Power Oct 14 '14 at 20:33
  • could you post an example along with the expected output? – Avinash Raj Oct 15 '14 at 06:14

1 Answers1

0

The syntax you use is rather strange. Why do you use ^ and $ anyway?

One can use the following regex:

s/\s+/-/g

s means you will substitute an occurence. g means it is global: all matches should be replaced.

Using a tool like sed or perl.

Example with sed:

sed -r 's/\s+/-/' < file
Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555