More informative return value for Regexp

L

Logan Capaldo

Is there a way to get a Regexp to tell you if it didn't match because
it won't match with the current input, or if it doesn't match (yet)
but potentially could with more input? Failing that, is there an
alternative regexp library for ruby that will allow that? I ask
becasue I'd like to do something along the lines of:

File.open(some_file) do |f|
f.scan(/a regex/) do |res|
# do something with res
end
end

I realise I could just load the whole file into memory, but that seems
kind of well, icky.
 
A

Austin Ziegler

Is there a way to get a Regexp to tell you if it didn't match because
it won't match with the current input, or if it doesn't match (yet)
but potentially could with more input? Failing that, is there an
alternative regexp library for ruby that will allow that? I ask
becasue I'd like to do something along the lines of:
=20
File.open(some_file) do |f|
f.scan(/a regex/) do |res|
# do something with res
end
end
=20
I realise I could just load the whole file into memory, but that seems
kind of well, icky.

There is a discussion around something related to this on RCRchive.
The upshot of the discussion is that it is not possible with regexen
in general, and lies way outside of the bounds of regexen.

-austin
--=20
Austin Ziegler * (e-mail address removed)
* Alternate: (e-mail address removed)
 
J

John Carter

Is there a way to get a Regexp to tell you if it didn't match because
it won't match with the current input, or if it doesn't match (yet)
but potentially could with more input? Failing that, is there an
alternative regexp library for ruby that will allow that? I ask
becasue I'd like to do something along the lines of:

Add your voice to RCR179
http://www.rcrchive.net/rcr/show/179



John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : (e-mail address removed)
New Zealand


Somewhere on the edge of a Galaxy, one of literally billions of such
galaxies, is a sun, one of literally billions of suns in that
galaxy.
 
G

gwtmp01

I've wanted this functionality in the past. I always thought of it
in the context of accepting interactive input. As someone was typing
you could provide input as to whether the partial string would be
rejected, might be accepted, or was already valid. Simple example
would be a 5-digit zip code field. As long as the user was typing
digits the UI could indicate "ok so far". If they typed a non-digit
the UI could indicate "no good" and at the point they had typed
exactly five digits the UI could indicate "acceptable as is". If
the user continued typing beyond the five digits, the UI would indicate
"no good".

Gary Wright
 
L

Logan Capaldo

=20
There is a discussion around something related to this on RCRchive.
The upshot of the discussion is that it is not possible with regexen
in general, and lies way outside of the bounds of regexen.
=20
-austin
--
Austin Ziegler * (e-mail address removed)
* Alternate: (e-mail address removed)
=20
=20

Aha. So much for that idea.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top