# STREAM Expression with exceptions

**URL:** <https://community.f5.com/t/stream-expression-with-exceptions/62437>\
**Category:** Technical Forums\
**Tags:** design, tmsh, tmos, deployment, irules, devops, application-delivery\
**Created:** [February 17, 2015, 4:14pm UTC](https://community.f5.com/t/stream-expression-with-exceptions/62437 "2015-02-17T16:14:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Narendra\_Babu](https://avatars.discourse-cdn.com/v4/letter/n/a5b964/32.png) [@Narendra\_Babu](https://community.f5.com/u/Narendra_Babu)\
**Post date:** [February 17, 2015, 4:14pm UTC](https://community.f5.com/t/stream-expression-with-exceptions/62437/1 "2015-02-17T16:14:40Z")

</div>

Hi all,

In my HTTP page (including form), i want to replace a string [domain.com](http://domain.com) to [domainservice.com](http://domainservice.com) But i don’t want to change if string is @domain.com.

I tried with multiple expressions with no luck

Can some one help me on this

Thanks

---

<div class="post-metadata">

**Author:** ![shaggy](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@shaggy](https://community.f5.com/u/shaggy)\
**Post date:** [February 17, 2015, 6:19pm UTC](https://community.f5.com/t/stream-expression-with-exceptions/62437/2 "2015-02-17T18:19:50Z")

</div>

are you using the stream profile or stream profile + iRule to apply your stream patterns?

---

<div class="post-metadata">

**Author:** ![StephanManthey](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@StephanManthey](https://community.f5.com/u/StephanManthey)\
**Post date:** [February 17, 2015, 6:37pm UTC](https://community.f5.com/t/stream-expression-with-exceptions/62437/3 "2015-02-17T18:37:15Z")

</div>

Hi Narendra,

in case you are using iRules the following will hopefully work for you as well:

```tcl
when HTTP_RESPONSE {
    STREAM::expression "\[^@\]comain\.comdomainservice\.com"
    STREAM::enable
}

```

Thanks, Stephan

---

<div class="post-metadata">

**Author:** ![giltjr](https://avatars.discourse-cdn.com/v4/letter/g/c4cdca/32.png) [@giltjr](https://community.f5.com/u/giltjr)\
**Post date:** [February 17, 2015, 8:35pm UTC](https://community.f5.com/t/stream-expression-with-exceptions/62437/4 "2015-02-17T20:35:12Z")

</div>

You might be able to use a “null” stream match along with STREAM\_MATCHED event.

Look at: [DevCentral - An F5 Technical Community](https://devcentral.f5.com/wiki/iRules.parse_username_from_http_requests_rule.ashx)

I don’t know exactly how stream works, that is does it “rescan” a string after it has found and done a a replace. Could you specify a second like:

```tcl
"domain\.comdomainservice\.com \@domainservice\.com\@domain.com"

```

Not sure if you have to escape and @ sign.

---

<div class="post-metadata">

**Author:** ![JG](https://avatars.discourse-cdn.com/v4/letter/j/dfb087/32.png) [@JG](https://community.f5.com/u/JG)\
**Post date:** [February 17, 2015, 10:46pm UTC](https://community.f5.com/t/stream-expression-with-exceptions/62437/5 "2015-02-17T22:46:54Z")

</div>

Try this:

```tcl
when HTTP_REQUEST {
    Disable the stream filter for all requests
   STREAM::disable

    LTM does not uncompress response content, so if the server has compression enabled
    and it cannot be disabled on the server, we can prevent the server from 
    sending a compressed response by removing the compression offerings from the client
   HTTP::header remove "Accept-Encoding"
}    
when HTTP_RESPONSE {
    STREAM::expression "@domain\.com domain\.comdomainservice.com"
    STREAM::enable
}
when STREAM_MATCHED {
    set matched_string [string tolower [STREAM::match]]
    if {$matched_string starts_with "@domain.com"} {
        STREAM::replace
        return
    }
}

```

---

<div class="post-metadata">

**Author:** ![StephanManthey](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@StephanManthey](https://community.f5.com/u/StephanManthey)\
**Post date:** [February 20, 2015, 3:17pm UTC](https://community.f5.com/t/stream-expression-with-exceptions/62437/6 "2015-02-20T15:17:35Z")

</div>

Hi again,

the following approach seems to work.

It seems to follow a longest match approach.

So the order of pattern mappings does not matter.

```tcl
when HTTP_REQUEST {
    STREAM::disable
}
when HTTP_RESPONSE {
    STREAM::expression {@domain\.com@domain.com domain\.comdomainservice.com}
    STREAM::enable
}

```

Tested on v11.5.1HF8.

Thanks, Stephan
