What does this reg expression mean?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lyn

    What does this reg expression mean?

    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

    #2
    Re: What does this reg expression mean?

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

    Perl regex, regular expression, extracting information, text processing


    Lyn wrote:
    [color=blue]
    > 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.[/color]
    [color=blue]
    > It looks like this:[/color]
    [color=blue]
    > ([^"]*)[/color]
    [color=blue]
    > 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?[/color]
    [color=blue]
    > Cheers,
    > Lyn[/color]


    Comment

    • Jürgen Exner

      #3
      Re: What does this reg expression mean?

      Lyn wrote:
      [...][color=blue]
      > 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?[/color]

      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


      Comment

      • magoo

        #4
        Re: What does this reg expression mean?

        In article <4%6mc.88856$G_ .75035@nwrddc02 .gnilink.net>,
        jurgenex@hotmai l.com says...[color=blue]
        > Lyn wrote:
        > [...][color=green]
        > > 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?[/color]
        >
        > 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
        >
        >
        >[/color]
        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

        Comment

        • Jürgen Exner

          #5
          Re: What does this reg expression mean?

          magoo wrote:[color=blue]
          > In article <4%6mc.88856$G_ .75035@nwrddc02 .gnilink.net>,
          > jurgenex@hotmai l.com says...[color=green]
          >> Inside of a character class the caret "^" looses it's special
          >> meaning and does not match beginning of the string any more.[/color][/color]
          [Wrong explanation snipped][color=blue]
          >
          > Shame on you for this bit of misinformation![/color]

          Ooops, you are right, of course
          [color=blue]
          > From the "Regular Expression Pocket Reference" by Tony Stubblebine:[/color]

          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


          Comment

          • Terry Michaels

            #6
            Re: What does this reg expression mean?


            "Jürgen Exner" <jurgenex@hotma il.com> wrote in message
            news:hEcmc.8900 2$G_.29787@nwrd dc02.gnilink.ne t...[color=blue]
            > magoo wrote:[color=green]
            > > In article <4%6mc.88856$G_ .75035@nwrddc02 .gnilink.net>,
            > > jurgenex@hotmai l.com says...[color=darkred]
            > >> Inside of a character class the caret "^" looses it's special
            > >> meaning and does not match beginning of the string any more.[/color][/color]
            > [Wrong explanation snipped][color=green]
            > >
            > > Shame on you for this bit of misinformation![/color]
            >
            > Ooops, you are right, of course
            >[color=green]
            > > From the "Regular Expression Pocket Reference" by Tony Stubblebine:[/color]
            >
            > 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
            >
            >[/color]

            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 ;>)


            Comment

            Working...