What does this reg expression mean?

Discussion in 'Perl' started by Lyn, May 5, 2004.

  1. Lyn

    Lyn Guest

    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
     
    Lyn, May 5, 2004
    #1
    1. Advertising

  2. Lyn

    view_as_html Guest

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

    http://www.anaesthetist.com/mnm/perl/regex.htm

    Lyn wrote:

    > 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
     
    view_as_html, May 5, 2004
    #2
    1. Advertising

  3. 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
     
    Jürgen Exner, May 5, 2004
    #3
  4. Lyn

    magoo Guest

    In article <4%6mc.88856$>,
    says...
    > 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
     
    magoo, May 5, 2004
    #4
  5. magoo wrote:
    > In article <4%6mc.88856$>,
    > says...
    >> 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
     
    Jürgen Exner, May 5, 2004
    #5
  6. "Jürgen Exner" <> wrote in message
    news:hEcmc.89002$...
    > magoo wrote:
    > > In article <4%6mc.88856$>,
    > > says...
    > >> 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 ;>)
     
    Terry Michaels, May 6, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roy Yao
    Replies:
    4
    Views:
    947
    Xenos
    Sep 19, 2003
  2. Roy Yao
    Replies:
    70
    Views:
    1,451
    jeffc
    Sep 23, 2003
  3. Li Ma
    Replies:
    1
    Views:
    2,282
    Roedy Green
    Mar 9, 2009
  4. Rahul
    Replies:
    4
    Views:
    578
    Robert Kern
    Apr 7, 2009
  5. C Barrington-Leigh
    Replies:
    1
    Views:
    1,209
    Tim Leslie
    Sep 10, 2010
Loading...

Share This Page