excluding text in quotes

General questions about using WildEdit

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

Post Reply
fuzzbug
Posts: 14
Joined: Sun Oct 07, 2007 10:47 pm
Location: Watford, UK

excluding text in quotes

Post 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?
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post 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
fuzzbug
Posts: 14
Joined: Sun Oct 07, 2007 10:47 pm
Location: Watford, UK

thank you, I think I understand that

Post 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)
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post 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. :-)
fuzzbug
Posts: 14
Joined: Sun Oct 07, 2007 10:47 pm
Location: Watford, UK

brackets? yes please!

Post 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?
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post 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.
fuzzbug
Posts: 14
Joined: Sun Oct 07, 2007 10:47 pm
Location: Watford, UK

Post 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?
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

We live in hope...
Post Reply