# Regexp question

**URL:** <https://community.f5.com/t/regexp-question/54910>\
**Category:** Technical Forums\
**Tags:** irules, dev, devops, application-delivery\
**Created:** [April 20, 2013, 8:34am UTC](https://community.f5.com/t/regexp-question/54910 "2013-04-20T08:34:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![soymanue](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@soymanue](https://community.f5.com/u/soymanue)\
**Post date:** [April 20, 2013, 8:34am UTC](https://community.f5.com/t/regexp-question/54910/1 "2013-04-20T08:34:22Z")

</div>

I want to build and iRule witch “SWITCH” command to make an URI based redirection.

If we have [http://www.mydomain.com/URI](http://www.mydomain.com/URI) y would need to redirect this way

if URI is “/marketing” or “/marketing/” → Redirection 1

if URI is “/accounting” or “/accounting/” → Redirection 2

if URI is “/humanresources” or “/humanresources/” → Redirection 2

How would you check with regexp if a string is client1, client1/ . Something like client1["/ ",]

Even better How would you check this:

“/MARKETING”

“/MARKETING/”

“/MARKETING/EN”

“/MARKETING/EN/”

“/HUMANRESURCES”

“/HUMANRESURCES/”

“”/HUMANRESURCES/EN"

“/HUMANRESURCES/EN/”

I was thinking abut inserting a final “/” if the string doesn’f end with one.

---

<div class="post-metadata">

**Author:** ![Kevin\_Stewart](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kevin_stewart/32/15267_2.png) [@Kevin\_Stewart](https://community.f5.com/u/Kevin_Stewart)\
**Post date:** [April 20, 2013, 12:53pm UTC](https://community.f5.com/t/regexp-question/54910/2 "2013-04-20T12:53:06Z")

</div>

You don’t even need a regex for something like this. Just use the **-glob** option of the switch command:

```tcl
switch -glob [string tolower [HTTP::uri]] {
     "/marketing*" { pool marketing_pool }
     "/accounting*" { pool accounting_pool }
     "/humanresources*" { pool hr_pool }
     default { pool default_pool }
}

```

---

<div class="post-metadata">

**Author:** ![soymanue](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@soymanue](https://community.f5.com/u/soymanue)\
**Post date:** [April 20, 2013, 1:17pm UTC](https://community.f5.com/t/regexp-question/54910/3 "2013-04-20T13:17:40Z")

</div>

Hi

Thanks for your help but it’s a bit more complicated:

Department =\> 16 different values

Language =\> 4 different values

/Department → /marketing/es/particulares/

/Department/ → /marketing/es/particulares/

/Department/Language \> \> /marketing/en/particulares/

/Department/Language/ → /marketing/en/particulares/

/Department/Language/ → no reditection

marketing/sp/

---

<div class="post-metadata">

**Author:** ![Kevin\_Stewart](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kevin_stewart/32/15267_2.png) [@Kevin\_Stewart](https://community.f5.com/u/Kevin_Stewart)\
**Post date:** [April 20, 2013, 1:53pm UTC](https://community.f5.com/t/regexp-question/54910/4 "2013-04-20T13:53:27Z")

</div>

I think the switch -glob would still probably work, as long as you search from most specific to least specific.

/department/language/

/department/language

/department/

/department

/
