Aliasing, and another regex question

J

J. Cooper

Is there a preferred way to alias inconveniently long things like
Oniguruma::ORegexp?

Is it possible to have one regex that matches all lines that have word
"foo", but only if word "bar" doesn't appear anywhere on the line?

Sorry for yet more questions!
 
S

Sebastian Hungerecker

J. Cooper said:
Is there a preferred way to alias inconveniently long things like
Oniguruma::ORegexp?

Well you can do something like OR = Oniguruma::ORegexp

Is it possible to have one regex that matches all lines that have word
"foo", but only if word "bar" doesn't appear anywhere on the line?

The best way would probably be to just use two regexen. One to select all
lines with foo and another to filter out those with bar.


HTH,
Sebastian
 
J

J. Cooper

Sounds good on the alias :)
The best way would probably be to just use two regexen. One to select
all
lines with foo and another to filter out those with bar.


HTH,
Sebastian

I figured... I was really hoping I could do it in one line, as this was
a regex I was using in a text editor (TextMate) to find all lines in a
group of files that contained one word but not another.

:(
 
S

Sebastian Hungerecker

J. Cooper said:
I was really hoping I could do it in one line

Well, you can do it in one line just not with a single regex (or maybe
you can do that too, but that'd probably more complicated and possibly
longer):
lines.select {|l| l =~ /foo/ && l !~ /bar/}


HTH,
Sebastian
 

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,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top