Page 1 of 1

excluding text in quotes

Posted: Fri Feb 29, 2008 11:10 am
by fuzzbug
I have a text file which I want to convert to a CSV.

All I would need to do is to convert <space> to comma to do this except for one complication, the file includes text in quotes and the spaces should not be removed from text in quotes.

Is there a regular expression which will tell WildEdit to replace all spaces with commas except if those spaces are within quotes?

Posted: Fri Feb 29, 2008 11:23 am
by ben_josephs
Here's one way to do it, using conditional expressions:
Find what: ( )|("[^"]*")
Replace with: ?1():?2($2)

[X] Regular expression
[X] Replacement format

thank you, I think I understand that

Posted: Fri Feb 29, 2008 12:12 pm
by fuzzbug
ben_josephs wrote:Here's one way to do it, using conditional expressions:
Find what: ( )|("[^"]*")
Replace with: ?1():?2($2)

[X] Regular expression
[X] Replacement format
Yes! Wow! I am impressed with both the tool and your understanding of it.

If I understand your suggestion correctly (and I probably don't!) to replace the spaces outside quotes with a comma I should say:
Find what: ( )|("[^"]*")
Replace with: ?1(,):?2($2)

Posted: Fri Feb 29, 2008 12:26 pm
by ben_josephs
Yes. Sorry, my mistake.

You can write the replacement expression equivalently as
?1,:?2$2
which has the virtue of being even more obscure. :-)

brackets? yes please!

Posted: Fri Feb 29, 2008 1:07 pm
by fuzzbug
ben_josephs wrote:Yes. Sorry, my mistake.

You can write the replacement expression equivalently as
?1,:?2$2
which has the virtue of being even more obscure. :-)
I think I'll keep the brackets, this regular expression business has my brain at the very edge of its abilities and dispensing with the brackets might just push me over the edge!

I brilliantly (!) figured out that the equivalent Find expression in TextPad is: \( \)\|\("[^"]*"\)
But I cannot figure out the TextPad equivalent of the replacement expression: ?1():?2($2)

Is there one?

Posted: Fri Feb 29, 2008 1:51 pm
by ben_josephs
Use Posix regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
Then you can use same regular expression as you did in WildEdit.

No, there is no equivalent in TextPad to WildEdit's fancy replacement expressions, or to many of its fancy regular expressions. (Note that a replacement expression is not a regular expression.) The regular expression engine used by TextPad is rather old and tired; WildEdit uses the Boost engine, which is far more powerful.

Posted: Fri Feb 29, 2008 3:36 pm
by fuzzbug
ben_josephs wrote:No, there is no equivalent in TextPad to WildEdit's fancy replacement expressions, or to many of its fancy regular expressions. (Note that a replacement expression is not a regular expression.) The regular expression engine used by TextPad is rather old and tired; WildEdit uses the Boost engine, which is far more powerful.
Thanks for all the help.

Is there going to be a new improved version of TextPad with Boost someday?

Posted: Fri Feb 29, 2008 6:22 pm
by ben_josephs
We live in hope...