For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

jgranieri_42214's avatar
jgranieri_42214
Icon for Nimbostratus rankNimbostratus
Jul 29, 2015

Need 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

  • 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
    }