Replace spaces with commas

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
dixonc
Posts: 54
Joined: Mon Feb 02, 2004 3:05 pm

Replace spaces with commas

Post by dixonc »

I've got some data:

Code: Select all

  Columns 1 through 6 

         Inf        5793        4096        3344        2896        2591

  Columns 7 through 12 

        2365        2189        2048        1931        1832        1747

  Columns 13 through 18 
and I want to get it into a list of numbers, separated by commas.

I've used ^\n to remove blank lines, ^.*Columns.*\n to remove lines with column on and ^ * to remove leading spaces (first bit of regular expression that I've attempted :D ).

How do I replace the spaces between numbers with a comma. I've tried * (space followed by *) but it doesn't work.

I know it's a simple thing but sadly my knowledge of regular expressions is simpler :(
dixonc
Posts: 54
Joined: Mon Feb 02, 2004 3:05 pm

Post by dixonc »

[ \t]+ seems to work - found more by luck than judgement!
User avatar
marbx
Posts: 2
Joined: Thu Jul 27, 2006 7:00 pm

Post by marbx »

The problem I see with matching " *" is that it'll match zero or more spaces - so this'll match between every character, because there are "zero or more" spaces between every character. The plus sign means to match one or more characters, so matching against " +" (space followed by plus) would probably also have worked for you. Now if there really are some tab characters in the document, you do need to use "[ \t]+", where the brackets mean to match any one of the included characters - a space or a tab.

Hmm, when I try matching " *" in Textpad, it hangs up on me. Presumably it fell into an infinite loop.

Also, the reason "^ *" works where " *" doesn't is because the carat "^" is an anchor. It tells the regex that this matches only at the beginning of a line. Click the "help" button in the replace dialog for a good description of how to use regular expressions.
Post Reply