Forum Moderators: coopster
search regex : "(_+)([a-zA-Z0-9]+)"
replace regex: "$2$1"
"foo_bar" it replaces it with "foobar_".
_foobar ---> foobar_
foobar_ ---> foobar_ (stays the same)
foo_bar ---> foo_bar (stays the same)
_foobar_ ---> _foobar_ (stays the same)
the ¦ is equal to a literal "or"
seo I misread your post (or rather rushed reading it) to begin with...
Just commenting on mincklerstraat's regex, I'd go along with what he has, though in your example you did mention underscores in the middle of words (that you don't want them replaced), which the above regex doens't take into account.
$subject = preg_replace('#\W+(_+)([a-zA-Z\-_0-9]+)\W+#', '$2$1', $subject);
It all depends on what you want to consitute as a "word". I've added a dash to qualify as a "word" character, you might want to include an apostrophe too.