Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Regular expression to match any line that DOESN'T begin with a particular string

1 view
Skip to first unread message

we...@att.net

unread,
Mar 22, 2006, 7:48:36 PM3/22/06
to
I would like to match lines that do NOT being with "http". Here is my
regex:

/^[^(http)]/

I am using a character class with negation and then counting on the
grouping to force negation of the entire "http" string.

Then of course, the first ^ anchors to the beginning of the string.

Is this correct?

Thanks,
Wes

A. Sinan Unur

unread,
Mar 22, 2006, 8:16:46 PM3/22/06
to
we...@att.net wrote in news:1143074916.738167.82330
@t31g2000cwb.googlegroups.com:

Of course not. You could have figured that out quite trivially yourself.

#!/usr/bin/perl

use strict;
use warnings;

while ( <DATA> ) {
print if /^[^(http)]/;
}

__DATA__
htpt

Compare that to

#!/usr/bin/perl

use strict;
use warnings;

while ( <DATA> ) {
print unless /^http/;
}

__DATA__
htpt

Sinan


--
A. Sinan Unur <1u...@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

Reeees

unread,
Mar 22, 2006, 8:22:43 PM3/22/06
to
A. Sinan Unur <1u...@llenroc.ude.invalid> trolled:

> we...@att.net wrote in news:1143074916.738167.82330
> @t31g2000cwb.googlegroups.com:

> > I would like to match lines that do NOT being with "http". Here is my
> > regex:
> >
> > /^[^(http)]/
> >
> > I am using a character class with negation and then counting on the
> > grouping to force negation of the entire "http" string.
> >
> > Then of course, the first ^ anchors to the beginning of the string.
> >
> > Is this correct?

> Of course not. You could have figured that out quite trivially yourself.

What is the purpose of this statement? How does this statement help
the user with his problem?

Some of you seem to think that it is ok to insult posters simply
because you may, or may not, be giving them accurate technical
advice. But it is not ok to insult people.

Please grow up. Or stop posting.

cordially, as always,

rm

John W. Krahn

unread,
Mar 22, 2006, 9:01:33 PM3/22/06
to

No, a character class is just a list of characters not a pattern so [^(http)]
is the same as [^()hpt]. You want a negative look-ahead assertion:

/(?!^http)/


John
--
use Perl;
program
fulfillment

Tad McClellan

unread,
Mar 23, 2006, 8:30:55 AM3/23/06
to


What happened when you tried it?


--
Tad McClellan SGML consulting
ta...@augustmail.com Perl programming
Fort Worth, Texas

Tom Regner

unread,
Mar 23, 2006, 8:55:49 AM3/23/06
to
Reeees wrote:

> A. Sinan Unur <1u...@llenroc.ude.invalid> trolled:
>> we...@att.net wrote in news:1143074916.738167.82330
>> @t31g2000cwb.googlegroups.com:
>
>> > I would like to match lines that do NOT being with "http". Here is my
>> > regex:
>> >
>> > /^[^(http)]/

[...]


>> >
>> > Is this correct?
>
>> Of course not. You could have figured that out quite trivially yourself.
>

[...]


>
> Some of you seem to think that it is ok to insult posters simply
> because you may, or may not, be giving them accurate technical
> advice. But it is not ok to insult people.

The phrase "could have trivially found that out yourself" is hardly an
insult, and in this case a simple fact, as the only thing the OP would have
had to do was run his code, his question (to remind you: "is this
correct?") would have been answered immediately (the answer is "no, it
isn't", the only correct answer, that A. Sinan Unur kindly accompanied with
a correct solution to the problem, which wasn't asked for by th OP...)

>
> Please grow up. Or stop posting.

likewise :)

regards,
Tom
--
Dievision GmbH | Kriegerstrasse 44 | 30161 Hannover
Telefon: (0511) 288791-0 | Telefax: (0511) 288791-99
http://www.dievision.de

Daniel

unread,
Mar 23, 2006, 12:14:43 PM3/23/06
to

John W. Krahn schrieb:

You're probably more likely to need something like this:

next if /^http/i;

or

return if /^http/i;

Which is actually the oposite of what you asked.

Daniel Cutter
print chr--$g+ord for'KWVX%GUW]RP^-^Tb]2[UXa\j#'=~m$.$g;

Peter J. Holzer

unread,
Mar 25, 2006, 7:32:31 AM3/25/06
to
Reeees wrote:
> A. Sinan Unur <1u...@llenroc.ude.invalid> trolled:
>> we...@att.net wrote in news:1143074916.738167.82330
>> @t31g2000cwb.googlegroups.com:
>> > I would like to match lines that do NOT being with "http". Here is
>> > my regex:
[...]

>> > Is this correct?
>
>> Of course not. You could have figured that out quite trivially
>> yourself.
>
> What is the purpose of this statement? How does this statement help
> the user with his problem?

It helps the user with his problem by introducing the idea of a test
case. Whenever you don't know whether your code is correct or not, try
to use it in a simple script which behaves differently whether it is
correct or not.

hp

--
_ | Peter J. Holzer | Löschung von at.usenet.schmankerl?
|_|_) | Sysadmin WSR/LUGA |
| | | h...@hjp.at | Diskussion derzeit in at.usenet.gruppen
__/ | http://www.hjp.at/ |

0 new messages