473,396 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

regexp search on infinite string?

Lets say i have a generator running that generates successive
characters of a 'string'
>From what I know, if I want to do a regexp search for a pattern of
characters then I would have to 'freeze' the generator and pass the
characters so far to re.search.
It is expensive to create successive characters, but caching could be
used for past characters. is it possible to wrap the generator in a
class, possibly inheriting from string, that would allow the regexp
searching of the string but without terminating the generator? In
other words duck typing for the usual string object needed by
re.search?

- Paddy.

Sep 14 '07 #1
3 1470
Paddy wrote:
Lets say i have a generator running that generates successive
characters of a 'string'
>>From what I know, if I want to do a regexp search for a pattern of
characters then I would have to 'freeze' the generator and pass the
characters so far to re.search.
It is expensive to create successive characters, but caching could be
used for past characters. is it possible to wrap the generator in a
class, possibly inheriting from string, that would allow the regexp
searching of the string but without terminating the generator? In
other words duck typing for the usual string object needed by
re.search?

- Paddy.
re.search & re.compile checks for str or unicode types explicitly, so
you need to turn your data into one of those before using the module.

buffer = []
while True:
buffer.append(mygerator.next())
m = re.search(pattern, "".join(buffer))
if m:
process(m)
buffer = []

James

Sep 15 '07 #2
On Sep 15, 2:57 am, James Stroud <jstr...@mbi.ucla.eduwrote:
Paddy wrote:
Lets say i have a generator running that generates successive
characters of a 'string'
>From what I know, if I want to do a regexp search for a pattern of
characters then I would have to 'freeze' the generator and pass the
characters so far to re.search.
It is expensive to create successive characters, but caching could be
used for past characters. is it possible to wrap the generator in a
class, possibly inheriting from string, that would allow the regexp
searching of the string but without terminating the generator? In
other words duck typing for the usual string object needed by
re.search?
- Paddy.

re.search & re.compile checks for str or unicode types explicitly, so
you need to turn your data into one of those before using the module.

buffer = []
while True:
buffer.append(mygerator.next())
m = re.search(pattern, "".join(buffer))
if m:
process(m)
buffer = []

James
Thanks James.

Sep 15 '07 #3
On Sep 15, 4:36 pm, Paddy <paddy3...@googlemail.comwrote:
On Sep 15, 2:57 am, James Stroud <jstr...@mbi.ucla.eduwrote:
Paddy wrote:
Lets say i have a generator running that generates successive
characters of a 'string'
>>From what I know, if I want to do a regexp search for a pattern of
characters then I would have to 'freeze' the generator and pass the
characters so far to re.search.
It is expensive to create successive characters, but caching could be
used for past characters. is it possible to wrap the generator in a
class, possibly inheriting from string, that would allow the regexp
searching of the string but without terminating the generator? In
other words duck typing for the usual string object needed by
re.search?
- Paddy.
re.search & re.compile checks for str or unicode types explicitly, so
you need to turn your data into one of those before using the module.
Aaaarbejaysus. Since when?
>>import array
ba = array.array('c', 'A hollow voice says "Plugh".')
import re
mobj = re.search('voi', ba)
mobj
<_sre.SRE_Match object at 0x00B99598>
>>mobj.span()
(9, 12)
>>>
>
buffer = []
while True:
buffer.append(mygerator.next())
m = re.search(pattern, "".join(buffer))
if m:
process(m)
buffer = []
James

Thanks James.
So:
buffer = array.array('c')
and flick the "".join() etc etc

HTH,
John

Sep 15 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Anand Pillai | last post by:
To search a word in a group of words, say a paragraph or a web page, would a string search or a regexp search be faster? The string search would of course be, if str.find(substr) != -1:...
4
by: Paul Rubin | last post by:
I have a string s, possibly megabytes in size, and two regexps, p and q. I want to find the first occurence of q that occurs after the first occurence of p. Is there a reasonable way to do it?...
5
by: Lukas Holcik | last post by:
Hi everyone! How can I simply search text for regexps (lets say <a href="(.*?)">(.*?)</a>) and save all URLs(1) and link contents(2) in a dictionary { name : URL}? In a single pass if it could....
6
by: Rizyak | last post by:
******************** alt.php.sql,comp databases.ms-sqlserver microsoft.public.sqlserver.programming *********************************** Why doesn't this work: SELECT * FROM 'Events'
26
by: Matt Kruse | last post by:
Are there any current browsers that have Javascript support, but not RegExp support? For example, cell phone browsers, blackberrys, or other "minimal" browsers? I know that someone using Netscape...
7
by: arno | last post by:
Hi, I want to search a substring within a string : fonction (str, substr) { if (str.search(substr) != -1) { // do something } }
11
by: HopfZ | last post by:
I coudn't understand some behavior of RegExp.test function. Example html code: ---------------- <html><head></head><body><script type="text/javascript"> var r = /^https?:\/\//g;...
11
by: Flyzone | last post by:
Hello, i have again problem with regexp :-P I need to match all lines that contain one word but not contain another. Like to do "grep one | grep -v two:" The syntax of the string is: (any...
8
by: Ben Amada | last post by:
Hi all. I know very little about regular expressions, but wanted to use one to validate an email address a user would be entering before the form is submitted. There are many examples out there. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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
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,...

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.