[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Aliasing, and another regex question

J. Cooper

2/27/2008 6:31:00 PM

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!
--
Posted via http://www.ruby-....

4 Answers

Avdi Grimm

2/27/2008 6:43:00 PM

0

On Wed, Feb 27, 2008 at 1:30 PM, J. Cooper <nefigah@gmail.com> wrote:
> Is there a preferred way to alias inconveniently long things like
> Oniguruma::ORegexp?

OReg = Oniguruma::ORegexp

--
Avdi

Sebastian Hungerecker

2/27/2008 6:50:00 PM

0

J. Cooper wrote:
> 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
--
Jabber: sepp2k@jabber.org
ICQ: 205544826

J. Cooper

2/27/2008 6:58:00 PM

0

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.

:(

--
Posted via http://www.ruby-....

Sebastian Hungerecker

2/27/2008 7:21:00 PM

0

J. Cooper wrote:
> 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
--
Jabber: sepp2k@jabber.org
ICQ: 205544826