DRYing a Regex

R

RichardOnRails

Hi,

I got a routine that works fine at building an array of upper-case
string extracting from a string:

while not s.eos?
if s.skip(/[A-Z]+/)
aNewList << s.matched
else
s.skip(/[^A-Z]+/)
end
end

I'd like to say something like the following. But !r doesn't work.
Can a Regex be negated somehow?

r = /[A-Z]+/
while not s.eos?
if s.skip(r)
aNewList << s.matched
else
s.skip(!r) # Doesn't work, of course. What does?
end
end

Thanks in advance,
Richard
 
I

Ian Collins

RichardOnRails said:
Hi,

I got a routine that works fine at building an array of upper-case
string extracting from a string:

while not s.eos?

Try a group for the language you are using!
 

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
474,156
Messages
2,570,878
Members
47,408
Latest member
AlenaRay88

Latest Threads

Top