Forum Discussion
jgranieri_42214
Nimbostratus
Jul 29, 2015Need to apply regex to a variable
Hello,
I have a need for regex to find the 2nd occurrence of a character and capture the data until the end. I tested my regex here and confirmed this regex will do what I need it to "[^@]+$". My issue is that when I test this via a simple irule the TCL regex doesn't seem to work at all. Any pointers would be great.
when CLIENT_ACCEPTED {
set $Login "jeff@test1@bank1"
log local0. "TC login string is: $Login"
set Result {regexp /[^@]+$/ $Login}
log local0. "This is the parsed data $Result"
}
Expected result = bank1
1 Reply
- Kevin_Stewart
Employee
You're actually pretty close:
when RULE_INIT { set logon "jeff@test1@bank1" regexp {[^@]+$} $logon result log local0. $result }But you might be better off avoiding the regex with something more robust. Here's a few example options:
when RULE_INIT { set logon "jeff@test1@bank1" scan $logon {%*[^@]@%*[^@]@%s} result log local0. $result }or:
when RULE_INIT { set logon "jeff@test1@bank1" set result [string range $logon [expr [string last "@" $logon] +1] end] log local0. $result }
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
