473,498 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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?
Jul 17 '05 #1
3 1779
yes, there are functions for regular expressions
Jul 17 '05 #2
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4154
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
4
305
by: Steve | last post by:
Hi all I have to validate a password to determine whether or not it adheres to certain rules. For example, the password must contain at least 1 number, at least 1 uppercase character and at...
7
2176
by: Patient Guy | last post by:
Coding patterns for regular expressions is completely unintuitive, as far as I can see. I have been trying to write script that produces an array of attribute components within an HTML element. ...
4
5137
by: Együd Csaba | last post by:
Hi All, I'd like to "compress" the following two filter expressions into one - assuming that it makes sense regarding query execution performance. .... where (adate LIKE "2004.01.10 __:30" or...
6
2270
by: Ludwig | last post by:
Hi, i'm using the regular expression \b\w to find the beginning of a word, in my C# application. If the word is 'public', for example, it works. However, if the word is '<public', it does not...
15
16684
by: Mark Rae | last post by:
Hi, I'm trying to construct a RegEx pattern which will validate a string so that it can contain: only the numerical characters from 0 to 9 i.e. no decimal points, negative signs, exponentials...
25
5128
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
3
2733
by: Zeba | last post by:
Hi guys, I need some help regarding regular expressions. Consider the following statement : System.Text.RegularExpressions.Match match =...
2
2114
by: John Nagle | last post by:
Regular expressions are compiled in ASCII mode unless Unicode mode is specified to "rc.compile". The difference is that regular expressions in ASCII mode don't recognize things like Unicode...
0
7002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7165
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7203
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5462
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4908
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4588
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3081
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.