# BIG-IP : irule class match with wildcards

**URL:** <https://community.f5.com/t/big-ip-irule-class-match-with-wildcards/18152>\
**Category:** Technical Forums\
**Tags:** design, irules, devops, ltm, application-delivery\
**Created:** [May 7, 2015, 12:16am UTC](https://community.f5.com/t/big-ip-irule-class-match-with-wildcards/18152 "2015-05-07T00:16:42Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![BaltoStar\_12467](https://avatars.discourse-cdn.com/v4/letter/b/df705f/32.png) [@BaltoStar\_12467](https://community.f5.com/u/BaltoStar_12467)\
**Post date:** [May 7, 2015, 12:16am UTC](https://community.f5.com/t/big-ip-irule-class-match-with-wildcards/18152/1 "2015-05-07T00:16:42Z")

</div>

F5 BIG-IP Virtual Edition v11.4.1 (Build 635.0) LTM on ESXi

Can

```tcl
[class match]

```

be used to match its arg against a list of strings containing wildcards ?

```tcl
[class match [string tolower [HTTP::path]] contains whitelist]

```

```tcl
whitelist

```

data-group

```tcl
"/default.html"
"/desert-dwellers/camel.html"
"/amphibians/*"
"/kids-favorites-*"
"/smelly/goat-*-juvenile"

```

So all of the following paths would match positive against

```tcl
whitelist

```

:

```tcl
`"default.html"
"/desert-dwellers/camel.html"
"/amphibians/platypus.html"
"/kids-favorites-1.html"
"/kids-favorites-2.html"
"/smelly/goat-billy-juvenile"
"/smelly/goat-nanny-juvenile"

```

If

```tcl
[class match]

```

data-group does not support wildcards is there another syntax possible - such as partial-matching ( left-to-right ) of any entry in the data-group ?

---

<div class="post-metadata">

**Author:** ![nitass](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/nitass/32/2270_2.png) [@nitass](https://community.f5.com/u/nitass)\
**Post date:** [May 7, 2015, 6:04am UTC](https://community.f5.com/t/big-ip-irule-class-match-with-wildcards/18152/2 "2015-05-07T06:04:39Z")

</div>

Can [class match] be used to match its arg against a list of strings containing wildcards ?

i do not think so.

anyway, since you are using contains, why don’t you remove asterisk in the data group?

```tcl
"/default.html"
"/desert-dwellers/camel.html"
"/amphibians/"
"/kids-favorites-"

```

---

<div class="post-metadata">

**Author:** ![nitass\_89166](https://avatars.discourse-cdn.com/v4/letter/n/9fc29f/32.png) [@nitass\_89166](https://community.f5.com/u/nitass_89166)\
**Post date:** [May 7, 2015, 6:04am UTC](https://community.f5.com/t/big-ip-irule-class-match-with-wildcards/18152/3 "2015-05-07T06:04:39Z")

</div>

Can [class match] be used to match its arg against a list of strings containing wildcards ?

i do not think so.

anyway, since you are using contains, why don’t you remove asterisk in the data group?

```tcl
"/default.html"
"/desert-dwellers/camel.html"
"/amphibians/"
"/kids-favorites-"

```

---

<div class="post-metadata">

**Author:** ![Samir\_Jha\_52506](https://avatars.discourse-cdn.com/v4/letter/s/a6a055/32.png) [@Samir\_Jha\_52506](https://community.f5.com/u/Samir_Jha_52506)\
**Post date:** [May 7, 2015, 6:07am UTC](https://community.f5.com/t/big-ip-irule-class-match-with-wildcards/18152/4 "2015-05-07T06:07:31Z")

</div>

i do not think you need asterisk (\*) in data group since you are using class match. Can you please try this.

```tcl
whitelist

```

data-group

```tcl
"/default.html"
    "/desert-dwellers/camel.html"
    "/amphibians/platypus.html"
    "/kids-favorites-1.html"
    "/kids-favorites-2.html"

```

```tcl
iRule

```

```tcl
when HTTP_REQUEST {
         if { [matchclass [HTTP::uri] starts_with whitelist] } {
            HTTP::redirect "http://www.xyz.com"
                }
            }

```

---

<div class="post-metadata">

**Author:** ![BaltoStar\_12467](https://avatars.discourse-cdn.com/v4/letter/b/df705f/32.png) [@BaltoStar\_12467](https://community.f5.com/u/BaltoStar_12467)\
**Post date:** [May 7, 2015, 6:21am UTC](https://community.f5.com/t/big-ip-irule-class-match-with-wildcards/18152/5 "2015-05-07T06:21:41Z")

</div>

thanks nitass yes that works for data-group list items i posted - but what about “/smelly/goat-\*-juvenile” or similar mid-match ?

---

<div class="post-metadata">

**Author:** ![BaltoStar\_12467](https://avatars.discourse-cdn.com/v4/letter/b/df705f/32.png) [@BaltoStar\_12467](https://community.f5.com/u/BaltoStar_12467)\
**Post date:** [May 7, 2015, 6:21am UTC](https://community.f5.com/t/big-ip-irule-class-match-with-wildcards/18152/6 "2015-05-07T06:21:41Z")

</div>

thanks nitass yes that works for data-group list items i posted - but what about “/smelly/goat-\*-juvenile” or similar mid-match ?

---

<div class="post-metadata">

**Author:** ![nitass\_89166](https://avatars.discourse-cdn.com/v4/letter/n/9fc29f/32.png) [@nitass\_89166](https://community.f5.com/u/nitass_89166)\
**Post date:** [May 7, 2015, 6:22am UTC](https://community.f5.com/t/big-ip-irule-class-match-with-wildcards/18152/7 "2015-05-07T06:22:59Z")

</div>

you are right. mid-match won’t work. there is no simple solution yet.

---

<div class="post-metadata">

**Author:** ![nitass](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/nitass/32/2270_2.png) [@nitass](https://community.f5.com/u/nitass)\
**Post date:** [May 7, 2015, 6:22am UTC](https://community.f5.com/t/big-ip-irule-class-match-with-wildcards/18152/8 "2015-05-07T06:22:59Z")

</div>

you are right. mid-match won’t work. there is no simple solution yet.

---

<div class="post-metadata">

**Author:** ![Greg\_Chew\_31149](https://avatars.discourse-cdn.com/v4/letter/g/45deac/32.png) [@Greg\_Chew\_31149](https://community.f5.com/u/Greg_Chew_31149)\
**Post date:** [May 7, 2015, 2:44pm UTC](https://community.f5.com/t/big-ip-irule-class-match-with-wildcards/18152/9 "2015-05-07T14:44:44Z")

</div>

for left to right match, could “starts with” work instead of “contains”? [https://devcentral.f5.com/wiki/iRules.class.ashx](https://devcentral.f5.com/wiki/iRules.class.ashx)

---

<div class="post-metadata">

**Author:** ![Stan\_Ward](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@Stan\_Ward](https://community.f5.com/u/Stan_Ward)\
**Post date:** [August 5, 2020, 5:34pm UTC](https://community.f5.com/t/big-ip-irule-class-match-with-wildcards/18152/10 "2020-08-05T17:34:39Z")

</div>

This is an old thread, but I’ve encountered a similar requirement, and am considering the following.: doing a search on the data-group and iterating over the entire list. The keys would be RegEx match strings and the values would be RegEx translation strings. It means that the RegEx compare of the source URL must happen against each returned search item using a RegEx compare. It loses the benefit of the more efficient list searching of class, but still allows storing the match and translation entries in a data-group with any conceivable match or translation rule.

The use case is a generic redirector with 1500+ entries, some of which have strange mapping requirements, i.e.

\*.domainA.com/[path1 | path2]/index.jsp → \*.domainB.com/path3/index.jsp

\*.domainA.com/\*/index.jsp → \*.domainB.com/\*/index.jsp

where both the hostname and the path have mappings to be done, and we can’t enumerate all the possible combinations as explicit rules (we literally don’t know what values are legal). Ugly, but not very high volume; mostly used for situations where we acquired a domain and the old function has been split in to two new destinations; we expect them to bookmark the new URL once they are there.

Most of the rules are not nearly that complicated, so perhaps it could be two data groups, one for the 95% case that can do a normal class match '‘starts\_with’ or ‘contains’, and if that doesn’t hit, search the second one for the ugly stuff. The value can be a RegEx translation string in either case; it’s the wildcard source that is the problem.
