tags:

views:

91

answers:

5

I have something like-

[[59],
[73 41],
[52 40 09],
[26 53 06 34],
[10 51 87 86 81],
[61 95 66 57 25 68]]

I need to add a comma before every space to be like -

[[59],
[73, 41],
[52, 40, 09],
[26, 53, 06, 34],
[10, 51, 87, 86, 81],
[61, 95, 66, 57, 25, 68]]

What would be regex string for that?

+2  A: 

This depends on what regex flavor you are using but in general, looking for matches would be

(\d+)\s

and replacing would be

\1,
Lieven
It doesn't work Lieven.. :(
What doesn't? The find or the replace? Note that the replace has a trailing space (I forgot to mention that in the answer)
Lieven
+5  A: 

Judging from your data, you may just replace a space ' ' by a comma followed by a space ', '. You do not need a regex for that.

Peter van der Heijden
A: 
s/\( \)/,\1/g

And, as an afterthought:

s/ /, /g

Why bother with substitution replacement? :)

Autocracy
+2  A: 

In Notepad++, open up the find control window with Ctrl+H.

  • In Find What put a single space character
  • In Replace With put a comma followed by a space character

This gives the expected output, but isn't very interesting as far as Regexes go.

Ian Potter
A: 

Replace (\d)\s(\d) with \1, \2