regular expressions, one character at a time

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

    regular expressions, one character at a time

    say i wanted to match a string to a regular expression, but i was only
    given the string one character at a time.

    one way to do this would be to evaluate the most recently submitted
    character along with every previously submitted character, however,
    that way seems like it would be unnecessarily inefficient.

    another way i can see of doing this would be to have a function that
    can access the previous state and return the state that the new
    character would put it in. this state could then be tested to see if
    it was an accept state, and if it was, it'd accept.

    the later method - the one that returns the current state - is the one
    i want to use. however, i'm not really sure how to go about doing it.
    any ideas?

    is there some library or package that includes this functionality, or
    will i have to implement it, myself?
  • Christopher-Robin

    #2
    Re: regular expressions, one character at a time

    yes, there are functions for regular expressions


    Comment

    • yawnmoth

      #3
      Re: regular expressions, one character at a time

      On Sat, 25 Sep 2004 16:41:28 +0200, "Christophe r-Robin"
      <Christopher-Robin@gmx.de> wrote:
      [color=blue]
      >yes, there are functions for regular expressions
      >[/color]

      that's not what i was asking...

      the regular expression functions included in php require that you have
      the *entire* string before parsing it with regular expressions. i,
      however, am *not* going to have the entire string. i would like to
      test it one character at a time. say i wanted to see if string X
      matched the regular expression "/123/", but that I'd only get string X
      a character at a time.

      i could do this:

      $string = '';
      while we're recieving the characters of string X as $x {
      $string .= $x;
      }
      preg_match('/123/',$string);

      or i could do this:

      $string = '';
      while we're recieving the characters of string X as $x {
      $state = match_function_ i_want($state,$ x);
      $string .= $x;
      }

      what could i replace match_function_ i_want with to get the
      functionality that i, well... want?

      Comment

      • Chung Leong

        #4
        Re: regular expressions, one character at a time

        "yawnmoth" <terra1024@yaho o.com> wrote in message
        news:a0d63404.0 409232110.159c6 00c@posting.goo gle.com...[color=blue]
        > say i wanted to match a string to a regular expression, but i was only
        > given the string one character at a time.
        >
        > one way to do this would be to evaluate the most recently submitted
        > character along with every previously submitted character, however,
        > that way seems like it would be unnecessarily inefficient.
        >
        > another way i can see of doing this would be to have a function that
        > can access the previous state and return the state that the new
        > character would put it in. this state could then be tested to see if
        > it was an accept state, and if it was, it'd accept.
        >
        > the later method - the one that returns the current state - is the one
        > i want to use. however, i'm not really sure how to go about doing it.
        > any ideas?[/color]

        Nope, there isn't a function for that. And besides, there's isn't really a
        previous state the regular expression engine can return to, since on a
        failure to match the engine would backtrack.


        Comment

        Working...