# String match unexpected behavior

**URL:** <https://community.f5.com/t/string-match-unexpected-behavior/45892>\
**Category:** Technical Forums\
**Tags:** irules, ltm, application-delivery\
**Created:** [February 18, 2016, 6:36pm UTC](https://community.f5.com/t/string-match-unexpected-behavior/45892 "2016-02-18T18:36:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nick\_T1](https://avatars.discourse-cdn.com/v4/letter/n/ecccb3/32.png) [@Nick\_T1](https://community.f5.com/u/Nick_T1)\
**Post date:** [February 18, 2016, 6:36pm UTC](https://community.f5.com/t/string-match-unexpected-behavior/45892/1 "2016-02-18T18:36:51Z")

</div>

Hello all! I’m trying to implement string match for the following condition and am not coming up with the right combination of options and looking at tcl wiki didn’t yield anything yet. In one irule (traffic\_split), I setup a pattern and in my final irule (pool\_mapping) I check for this test condition and override if it is met. The following works (I know its not exactly regex)

excerpt from traffic\_split:

```tcl
set test_host "www.fool.com"
set test_path_regex "\/investing\/general\/2016\/*"
set test_percentage 10

```

excerpt from pool\_mapping:

```tcl
if {[info exists test_cookie_name]}{
    if {[HTTP::cookie exists $test_cookie_name] && $host equals $test_host && [string match -nocase $test_path_regex $path] }{
      if { [HTTP::cookie value $test_cookie_name] <= $test_percentage }{
        set tmfpool $test_pool
      }
    }
  }

```

So, when requesting this URL, it works: [The Agony of High Returns | The Motley Fool](http://www.fool.com/investing/general/2016/02/09/the-agony-of-high-returns.aspx)

However, the developers of the application noted that there was some errant traffic being sent to them, example: [http://www.fool.com/investing/general/2016/02/09/atom.xml](http://www.fool.com/investing/general/2016/02/09/atom.xml)

So, I thought just using something like one of the following, none of which worked:

```tcl
set test_path_regex "\/investing\/general\/2016\/*\.aspx"
set test_path_regex "\/investing\/general\/2016\/.*\.aspx"
set test_path_regex "\/investing\/general\/2016\/*\.aspx$"
set test_path_regex "\/investing\/general\/2016\/.*\.aspx$"

```

Am I missing something, unimplemented by design, or something else entirely?

---

<div class="post-metadata">

**Author:** ![Kai\_Wilke](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kai_wilke/32/24646_2.png) [@Kai\_Wilke](https://community.f5.com/u/Kai_Wilke)\
**Post date:** [February 18, 2016, 6:47pm UTC](https://community.f5.com/t/string-match-unexpected-behavior/45892/2 "2016-02-18T18:47:49Z")

</div>

Hi Nick,

the command

```tcl
[string match -nocase $test_path_regex $path]

```

isn’t using RegEx. Its rather using a

```tcl
-glob

```

matching syntax (

```tcl
*

```

,

```tcl
?

```

or

```tcl
[A-Za-z0-9]

```

wildcards). So just use…

```tcl
set test_path_regex "/investing/general/2016/*.aspx"
set test_path_regex "/investing/general/2016/*.aspx*"

```

For more information: [http://www.tcl.tk/man/tcl8.4/TclCmd/string.htmM34](http://www.tcl.tk/man/tcl8.4/TclCmd/string.htmM34)

General Note: You should avoid using RegEx in iRules as much as possible. Its terible slow and most of the stuff can be already done using -glob matchings.

Cheers, Kai
