Forum Discussion
gerald_wegener_
Nimbostratus
Jul 11, 2005Regsub always returns a 1 never 0
I've tried running the script that is posted which uses regsub to search for Social Security Numbers in the form xxx-xx-xxxx. I've tried several different permuations of this but can never get anything but a value of "1" for $new_response1.
Click here to see the link to the iRule:
http://devcentral.f5.com/Default.aspx?TabID=29&newsType=ArticleView&articleId=25
The line in the last section:
if {$new_response1 !=0} {
then replace content...
}
Always returns a value of 1, even if there is no SSN found. I'm guessing that someone used != 0 to get it to work since it is never set to 0. i.e. if no SS is found.
- unRuleY_95363Historic F5 AccountYes, that example is wrong. Here is the correct HTTP_RESPONSE_DATA:
when HTTP_RESPONSE_DATA { set payload [HTTP::payload [HTTP::payload length]] set ssnx “xxx-xxx-xxxx” Find the SSN numbers if { [regsub -all {\d{3}-\d{2}-\d{4}} $payload $ssnx new_response] > 0 } { Replace the content if there was any matches HTTP::payload replace 0 [HTTP::payload length] $new_response } }
- gerald_wegener_
Nimbostratus
- unRuleY_95363Historic F5 AccountPerhaps it's because the regex isn't right. It looks light you have forward slashes / instead of backslashes \:
{/d{3}-/d{2}-/d{4}}
{\d{3}-\d{2}-\d{4}}
- gerald_wegener_
Nimbostratus
Thank you. That looks like it works. \ and / look the same to me at this point in my day! Is there a way for me to - unRuleY_95363Historic F5 AccountYou can use the Tcl command 'regexp' to match a regular expression and have it return the matched portions.
set card_nums [regexp -all -inline {\d{4}-\d{4}-\d{4}-\d{4}} $payload] if { $card_nums ne "" } { log "Found credit card numbers: $card_nums" }
- unRuleY_95363Historic F5 AccountUnfortunately, we have followed the standard for syslog (RFC3164) which states:
- unRuleY_95363Historic F5 AccountOh, I forgot to add that if you want to scrub the CC, then you'll likely want to change the regexp to --indices which will return a list of the start, end index of each match. You can then use string range to extract each card num for validation but then use the indices with the command "HTTP::payload replace " to scrub out the card number (replacing just sections of the payload is going to be more efficient than replacing the entire thing with a modified $payload variable).
- gerald_wegener_
Nimbostratus
Thank you. I tried combining the regsub's and it looks like - gerald_wegener_
Nimbostratus
I did some more troubleshooting on this. Best I can tell it looks like valid AMEX numbers are flagged as invalid and invalid numbers are flagged as valid, at least with a few test card numbers. - gerald_wegener_
Nimbostratus
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