# Aliasing, and another regex question

**URL:** <https://www.ruby-forum.com/t/aliasing-and-another-regex-question/130370>\
**Category:** Ruby\
**Created:** [February 27, 2008, 7:30pm UTC](https://www.ruby-forum.com/t/aliasing-and-another-regex-question/130370 "2008-02-27T19:30:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nefigah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e47774/32.png) [@nefigah](https://www.ruby-forum.com/u/nefigah)\
**Post date:** [February 27, 2008, 7:30pm UTC](https://www.ruby-forum.com/t/aliasing-and-another-regex-question/130370/1 "2008-02-27T19:30:58Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![nefigah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e47774/32.png) [@nefigah](https://www.ruby-forum.com/u/nefigah)\
**Post date:** [February 27, 2008, 7:51pm UTC](https://www.ruby-forum.com/t/aliasing-and-another-regex-question/130370/2 "2008-02-27T19:51:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nefigah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e47774/32.png) [@nefigah](https://www.ruby-forum.com/u/nefigah)\
**Post date:** [February 27, 2008, 7:43pm UTC](https://www.ruby-forum.com/t/aliasing-and-another-regex-question/130370/3 "2008-02-27T19:43:55Z")

</div>

On Wed, Feb 27, 2008 at 1:30 PM, J. Cooper [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

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

OReg = Oniguruma::ORegexp

---

<div class="post-metadata">

**Author:** ![nefigah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e47774/32.png) [@nefigah](https://www.ruby-forum.com/u/nefigah)\
**Post date:** [February 27, 2008, 7:58pm UTC](https://www.ruby-forum.com/t/aliasing-and-another-regex-question/130370/4 "2008-02-27T19:58:24Z")

</div>

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.

☹

---

<div class="post-metadata">

**Author:** ![nefigah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e47774/32.png) [@nefigah](https://www.ruby-forum.com/u/nefigah)\
**Post date:** [February 27, 2008, 8:21pm UTC](https://www.ruby-forum.com/t/aliasing-and-another-regex-question/130370/5 "2008-02-27T20:21:46Z")

</div>

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
