in reply to I just cannot figure out the greedy regex
I'm going to assume you're using something along the lines of s/".*"//gs; to do this. It would explain why your example text would be completely removed. One way to fix this would be to use the '?' character to indicate non-greediness: s/".*?"//gs;. A better way would be to use a negated character class. An example using this follows:
#!c:/perl/bin/perl -w $|++; use strict; my $txt = <<'TXT_DONE'; This is an "example", where all of the "quotes in this text" are removed, therefore cleansing the text of "all visible quotes". "So this quote", as well as "this quote here" will be stripped. TXT_DONE $txt =~ s/"[^"]+"//g; print $txt; __END__ This is an , where all of the are removed, therefore cleansing the text of . , as well as will be stripped.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: I just cannot figure out the greedy regex
by Roger (Parson) on Dec 16, 2003 at 05:33 UTC | |
by !1 (Hermit) on Dec 16, 2003 at 07:34 UTC |