By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,716 Members | 1,317 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,716 IT Pros & Developers. It's quick & easy.

regular expressions, one character at a time

P: n/a
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?
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
yes, there are functions for regular expressions
Jul 17 '05 #2

P: n/a
On Sat, 25 Sep 2004 16:41:28 +0200, "Christopher-Robin"
<Ch***************@gmx.de> wrote:
yes, there are functions for regular expressions


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?
Jul 17 '05 #3

P: n/a
"yawnmoth" <te*******@yahoo.com> wrote in message
news:a0**************************@posting.google.c om...
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?


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.
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.