473,385 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,385 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 12012
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.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.