# Anyone can help me to combine these 2 lines?

**URL:** <https://www.ruby-forum.com/t/anyone-can-help-me-to-combine-these-2-lines/188699>\
**Category:** NGINX\
**Created:** [May 16, 2010, 10:41pm UTC](https://www.ruby-forum.com/t/anyone-can-help-me-to-combine-these-2-lines/188699 "2010-05-16T22:41:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kamanwu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/43a26b/32.png) [@kamanwu](https://www.ruby-forum.com/u/kamanwu)\
**Post date:** [May 16, 2010, 10:41pm UTC](https://www.ruby-forum.com/t/anyone-can-help-me-to-combine-these-2-lines/188699/1 "2010-05-16T22:41:33Z")

</div>

I just want to set…if $http\_user\_agent equals AAA or BBB or empty  
(“”)…then return 400…Thanks…

```
if ($http_user_agent ~ (AAA|BBB)) {return 400;}
if ($http_user_agent = "") {return 400;}

```

Posted at Nginx Forum:

> **[anyone can help me to combine these 2 lines?](https://forum.nginx.org/read.php?2,87266,87266#msg-87266)**
>
> I just want to set.......if $http\_user\_agent equals AAA or BBB or empty ("").....then return 400...Thanks....... if ($http\_user\_agent ~ (AAA|BBB)) {return 400;} if ($http\_user\_agent = "") {return 400;}

---

<div class="post-metadata">

**Author:** ![kamanwu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/43a26b/32.png) [@kamanwu](https://www.ruby-forum.com/u/kamanwu)\
**Post date:** [May 16, 2010, 11:36pm UTC](https://www.ruby-forum.com/t/anyone-can-help-me-to-combine-these-2-lines/188699/2 "2010-05-16T23:36:34Z")

</div>

Try this:

if ($http\_user\_agent ~ “^(AAA|BBB|^.+)$”) {return 400;}

---

<div class="post-metadata">

**Author:** ![kamanwu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/43a26b/32.png) [@kamanwu](https://www.ruby-forum.com/u/kamanwu)\
**Post date:** [May 17, 2010, 12:15am UTC](https://www.ruby-forum.com/t/anyone-can-help-me-to-combine-these-2-lines/188699/3 "2010-05-17T00:15:47Z")

</div>

^.+ ??  
It means empty string?

Posted at Nginx Forum:

> **[Re: anyone can help me to combine these 2 lines?](https://forum.nginx.org/read.php?2,87266,87283#msg-87283)**
>
> I just want to set.......if $http\_user\_agent equals AAA or BBB or empty ("").....then return 400...Thanks....... if ($http\_user\_agent ~ (AAA|BBB)) {return 400;} if ($http\_user\_agent = "") {return 400;}

---

<div class="post-metadata">

**Author:** ![kamanwu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/43a26b/32.png) [@kamanwu](https://www.ruby-forum.com/u/kamanwu)\
**Post date:** [May 17, 2010, 12:23am UTC](https://www.ruby-forum.com/t/anyone-can-help-me-to-combine-these-2-lines/188699/4 "2010-05-17T00:23:59Z")

</div>

^(not).+(one or more of anything)

---

<div class="post-metadata">

**Author:** ![kamanwu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/43a26b/32.png) [@kamanwu](https://www.ruby-forum.com/u/kamanwu)\
**Post date:** [May 17, 2010, 12:23am UTC](https://www.ruby-forum.com/t/anyone-can-help-me-to-combine-these-2-lines/188699/5 "2010-05-17T00:23:59Z")

</div>

Can I write like this…?

if ($http\_user\_agent ~ (AAA|BBB|^$)) {return 400;}

Posted at Nginx Forum:

> **[Re: anyone can help me to combine these 2 lines?](https://forum.nginx.org/read.php?2,87266,87285#msg-87285)**
>
> I just want to set.......if $http\_user\_agent equals AAA or BBB or empty ("").....then return 400...Thanks....... if ($http\_user\_agent ~ (AAA|BBB)) {return 400;} if ($http\_user\_agent = "") {return 400;}

---

<div class="post-metadata">

**Author:** ![kamanwu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/43a26b/32.png) [@kamanwu](https://www.ruby-forum.com/u/kamanwu)\
**Post date:** [May 17, 2010, 12:33am UTC](https://www.ruby-forum.com/t/anyone-can-help-me-to-combine-these-2-lines/188699/6 "2010-05-17T00:33:56Z")

</div>

Yeah, that should work.
