473,231 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

Right regex to match -- comments or blank line?

Hi Folks:

I need the right regex to match either a comment line (--) or a blank line.
What I've got below doesn't seem to be working like I'd expect. I've posted
a snippet of what I have below...would anyone be kind enough to point me in
the right direction? I also apparently need to strip the ';' off the end
of the INSERT statement...

TIA,
Dave

-----------------------------------------------------------
while(<SCRIPT>) {

chomp;

$insert = $_;

unless ($insert =~ /^--|^\s+$\n/) {

$rv = $dbh->do($insert);

}

}

The script I'm reading in looks like this:

-- Some comments on this line, the next line is a blank line, then the next
lines are inserts.

insert into sometable values('whatever1');

insert into sometable values('whatever2');

etc.


Jul 19 '05 #1
3 12008
jan
chomp(); is removing the \n;

try:
unless ($insert =~ /^--|^\s?$/)

Cheers,
Jan

"Dave Sisk" <ds***@nc.rr.com.0nospam0> wrote in message news:<0Q*********************@twister.southeast.rr .com>...
Hi Folks:

I need the right regex to match either a comment line (--) or a blank line.
What I've got below doesn't seem to be working like I'd expect. I've posted
a snippet of what I have below...would anyone be kind enough to point me in
the right direction? I also apparently need to strip the ';' off the end
of the INSERT statement...

TIA,
Dave

-----------------------------------------------------------
while(<SCRIPT>) {

chomp;

$insert = $_;

unless ($insert =~ /^--|^\s+$\n/) {

$rv = $dbh->do($insert);

}

}

The script I'm reading in looks like this:

-- Some comments on this line, the next line is a blank line, then the next
lines are inserts.

insert into sometable values('whatever1');

insert into sometable values('whatever2');

etc.

Jul 19 '05 #2
"jan" <ja*@ossifrage.net> wrote in message
news:fc**************************@posting.google.c om...
chomp(); is removing the \n;


Actually it is removing whatever the value of $/ is. Granted, by default
that is \n, but some people may change it and wonder why chomp() doesn't
work any more.

jue
Jul 19 '05 #3
In article <fc**************************@posting.google.com >, jan
<ja*@ossifrage.net> wrote:

[top-posting fixed]
"Dave Sisk" <ds***@nc.rr.com.0nospam0> wrote in message
news:<0Q*********************@twister.southeast.rr .com>...
Hi Folks:

I need the right regex to match either a comment line (--) or a blank line.
What I've got below doesn't seem to be working like I'd expect. I've posted
a snippet of what I have below...would anyone be kind enough to point me in
the right direction? I also apparently need to strip the ';' off the end
of the INSERT statement...

TIA,
Dave

-----------------------------------------------------------
while(<SCRIPT>) {
chomp;
$insert = $_;
unless ($insert =~ /^--|^\s+$\n/) {
Do you want to allow for blanks before the '--'?
Do you require a blank line have whitespace in it?

If "yes" and "no", change to:
unless ( $insert =~ /^\s*--|^\s*$/ ) {

To strip off semi-colon at end:

$insert =~ s/;\s*$//;
$rv = $dbh->do($insert);
}
}

The script I'm reading in looks like this:

-- Some comments on this line, the next line is a blank line, then the next
lines are inserts.

insert into sometable values('whatever1');

insert into sometable values('whatever2');

etc.

chomp(); is removing the \n;

try:
unless ($insert =~ /^--|^\s?$/)

Cheers,
Jan


Note: this newsgroup is defunct. Try comp.lang.perl.misc in the future.
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Vishant | last post by:
Hi, I'm new to javascript and regEx and trying to solve the following problem. I have a function which validates the password if there is a number:...
2
by: Mr.Clean | last post by:
I am working on modifying a syntax highlighter written in javascript and it uses several regexes. I need to add a language to the avail highlighters and need the following regexes modified to...
2
by: Daniel Billingsley | last post by:
First, if MSFT is listening I'll say IMO the MSDN material is sorely lacking in this area... it's just a whole bunch of information thrown at you and you're left to yourself as to organizing it in...
8
by: rjb | last post by:
Hi! Could somebody have a look and help me to optimize the code below. It may look like very bad way of coding, but this stuff is very, very new for me. I've included just few lines. Regex...
5
by: JackRazz | last post by:
Anyone know the regular expression to match a blank line where the byte sequence is "0D 0A 0D 0A" ive tried "\r\n\r\n+", "^$+" "\n\r" with no success. Any Ideas? Thanks - JackRazz This is...
8
by: Bob | last post by:
I need to create a Regex to extract all strings (including quotations) from a C# or C++ source file. After being unsuccessful myself, I found this sample on the internet: ...
2
by: beatTheDevil | last post by:
Hey guys, As the title says I'm trying to make a regular expression (regex/regexp) for use in removing the comments from code. In this case, this particular regex is meant to match /* ... */...
2
by: GS | last post by:
How can one avoid capturing leading empty or blank lines? the data I deal with look like this "will be paid on the dates you specified. xyz supplier amount: $100.52 when: September 07,...
3
by: Jeff | last post by:
I'm parsing this: name="value" and sometimes it looks like this: name2="value2 without the closing '"'. I don't want to capture the end quote.
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.