What does this reg expression mean?

L

Lyn

I'm trying to get my head around regular expressions while
maintaining some semblance of sanity. I'm canabalising a
similar program to construct my own, and it keeps using an
expression I'm not familiar with as a pattern matcher.

It looks like this:

([^"]*)

To me, it looks like 0 or more occurences of the beginning of
a string or quote character, but that doesn't make much sense
in the context it's used. And it's used multiple times, so
I'm hoping it's a widely used trick that someone might be able
to explain to me?

Cheers,
Lyn
 
V

view_as_html

^ is the anchor here is a a good explanation on that

http://www.anaesthetist.com/mnm/perl/regex.htm
I'm trying to get my head around regular expressions while
maintaining some semblance of sanity. I'm canabalising a
similar program to construct my own, and it keeps using an
expression I'm not familiar with as a pattern matcher.
It looks like this:

To me, it looks like 0 or more occurences of the beginning of
a string or quote character, but that doesn't make much sense
in the context it's used. And it's used multiple times, so
I'm hoping it's a widely used trick that someone might be able
to explain to me?
 
J

Jürgen Exner

Lyn wrote:
[...]
It looks like this:

([^"]*)

To me, it looks like 0 or more occurences of the beginning of
a string or quote character, but that doesn't make much sense
in the context it's used. And it's used multiple times, so
I'm hoping it's a widely used trick that someone might be able
to explain to me?

Inside of a character class the caret "^" looses it's special meaning and
does not match beginning of the string any more.
So this RE matches any sequence of consecutive carets and double quotes.

jue
 
M

magoo

Lyn wrote:
[...]
It looks like this:

([^"]*)

To me, it looks like 0 or more occurences of the beginning of
a string or quote character, but that doesn't make much sense
in the context it's used. And it's used multiple times, so
I'm hoping it's a widely used trick that someone might be able
to explain to me?

Inside of a character class the caret "^" looses it's special meaning and
does not match beginning of the string any more.
So this RE matches any sequence of consecutive carets and double quotes.

jue
Jue,

Shame on you for this bit of misinformation!
From the "Regular Expression Pocket Reference" by Tony Stubblebine:

"Character classes are ways to define or specify a set of characters.
A character class matches one character in the input string that is
within the defined set.

Normal classes: [...] and [^...]
Character classes, [...], and negated character classes, [^...],
allow you to list the characters that you do or do not want to match.
(More info...)

So this RE, ([^"]*), captures zero or more occurrences of anything that
is not a double-quote. With the parentheses, there is capturing also
into a numbered variable, i.e., $1, $2 depending on how many previous
capturing parenthesis exist. Perhaps a better RE, in my mind, would be
([^"]+), i.e., one or more occurrences of anything not a double-quote.
The asterisk modifier would match zero or more of anything not a double-
quote which may or may not be what you want.

magoo
 
J

Jürgen Exner

magoo said:
Inside of a character class the caret "^" looses it's special
meaning and does not match beginning of the string any more.
[Wrong explanation snipped]

Shame on you for this bit of misinformation!

Ooops, you are right, of course
From the "Regular Expression Pocket Reference" by Tony Stubblebine:

However, does this book describe Perl REs or other REs?
I would rather check the Perl documentation because REs differ quite a bit
for different languages.

jue
 
T

Terry Michaels

Jürgen Exner said:
magoo said:
Inside of a character class the caret "^" looses it's special
meaning and does not match beginning of the string any more.
[Wrong explanation snipped]

Shame on you for this bit of misinformation!

Ooops, you are right, of course
From the "Regular Expression Pocket Reference" by Tony Stubblebine:

However, does this book describe Perl REs or other REs?
I would rather check the Perl documentation because REs differ quite a bit
for different languages.

jue

The book describes Perl RE's as well as others.
I don't have it in front of me, it is on my desk at work.
I just reached for the nearest reference I had at the time ;>)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top