PDA

View Full Version : regex - replace seond space in row


BubikolRamios
09-05-2010, 10:56 PM
a b c d
e f g h

can it be done with regex this:


a b","c d
e f","g h


that is, in each row replace ewery second space with ","
?

oracleguy
09-06-2010, 12:51 AM
Yeah you should be able to. Try using this regex, it will match every second space assuming the format you showed. If you want to be able to match every other space if the spaces are adjacent, this pattern won't work for that.

(.*?\s.*?(\s))+

BubikolRamios
09-06-2010, 07:10 AM
if I try this on one row, like:


a b c d

-->

","c d

so this is not it, for more rovs it obvioulsy does not work either.
at least, what should be used there is "positive look behind" or something, which I dont understand too welll.

BubikolRamios
09-06-2010, 01:41 PM
can anyone see why this does not work ?

((?<=(\S{1,}\s\S{1,}))\s)(?=(.*))

red is the space to be replaced

test string:

a b c d

replacing it with ", shuld give out:

a b"c d