0

I want a dash to be added at the end and beginning of a string.

Example:

"chicken" -> "-chicken-"  
"nuggets" -> "-nuggets-"  

So I'm pretty much asking for Regexes.

Cœur
  • 32,421
  • 21
  • 173
  • 232
Julian Avar
  • 478
  • 1
  • 5
  • 22
  • `sed s/.*/-&-/`. At least try next time. - Replace `.` with `[^ \t]` if you define a string as stuff between whitespace. – ShellFish Jun 15 '15 at 19:48

2 Answers2

1

You can use the following to match:

^|$

And replace with - (dash)

See DEMO

PS: Use it with m (multiline) flag.

karthik manchala
  • 13,025
  • 1
  • 27
  • 54
1

The regex is:

/^(.*)$/-\1-/

But why don't to add dashes without regex?

umka
  • 1,610
  • 1
  • 10
  • 18