Forum Discussion

____177053's avatar
Sep 11, 2017

How to count a letter in a string by irules?

We wants to count how many "a" or something else in a string using irules,How can we do that?

 

Thanks a lot!

 

1 Reply

  • JG's avatar
    JG
    Icon for Cumulonimbus rankCumulonimbus

     

    when CLIENT_ACCEPTED {
        set NEEDLE "a"
        set HAYSTACK "ababab"
        set NUMBER [llength [regexp -all -inline (?=$NEEDLE) $HAYSTACK]]
        log local0. "Number of instances of a found: $NUMBER"
    }