Gossamer Forum
Home : General : Perl Programming :

Regex help please

Quote Reply
Regex help please
I have been trying to write two regexes that will match all occurrences of ","newline (quotation comma quotation newline) and all occurrences of ","","","newline (quotation comma quotation quotation comma quotation quotation comma quotation newline). Can anyone help with this? I am searching a multiline document and the regexps are to put in a search and replace script.
Thanks.
Tony.
Quote Reply
Re: [tbalazs] Regex help please In reply to
[reply]I have been trying to write two regexes that will match all occurrences of ","newline (quotation comma quotation newline) and all occurrences of ","","","newline (quotation comma quotation quotation comma quotation quotation comma quotation newline). Can anyone help with this? I am searching a multiline document and the regexps are to put in a search and replace script.
Thanks.
Tony.[/reply]

Hi Tony,
Try this: $line2tabs=s/","/\t/g

You'll also need to add these two lines (to remove the beginning and ending quotes):
$line=~s/^"//;
$line=~s/"$//;

Hope this helps, or was what you were looking for,
Pam

P.S. be careful of working with some comma-delimited files. They don't put quotes around numbers. Those are a bit trickier and need additional lines.
Quote Reply
Re: [tbalazs] Regex help please In reply to
Something like this may work if I've understood your question...

Code:
if ($page =~ m/","(?:","",")?\n/s) {
die "Match";
}

You will find lots of useful information here:

http://www.perldoc.com/....6.1/pod/perlre.html

Last edited by:

PerlPod: Aug 21, 2002, 3:53 AM