// strip spaces from oldString var newString:String = String(oldString.replace( /s/g, "" ));
Tag Archive for regex
Strip spaces from a String with RegEx
Strong Password RegEx
(?=^.{8,}$)((?=.*d)|(?=.*W+))(?![.
])(?=.*[A-Z])(?=.*[a-z]).*$
Sanitize Input
function _codeSanitize($input, $methods) {
if (strlen($methods) > 0) {
if (in_array('alpha', $methods))
$input = ereg_replace("[A-Za-z]", "", $input);
if (in_array('numeric', $methods))
$input = ereg_replace("[0-9]", "", $input);
if (in_array('nonalphanumeric', $methods))
return ereg_replace("[^A-Za-z0-9]", "", $input);
}
return $input;
}
###
$dirty = '';
$sanitized = '';
if (@strlen($_POST['dirty']) > 0) {
$dirty = stripslashes(htmlspecialchars($_POST['dirty']));
@$sanitized = _codeSanitize($dirty, $_POST['methods']);
}
Fuzzy string matching with Perl
use String::Approx 'amatch';
use Test::More(no_plan);
sub fuzm {
$_ = shift;
return amatch("homer_simpson", [ # this array sets match options:
"i", # match case-insensitively
"10%", # tolerate up to 1 character in 10 being wrong
"S0", # but no substituting one character for another
"D1", # although, tolerate up to one deletion
"I2" # and tolerate up to two insertions
]);
}
ok(fuzm("homer_simpson"), "exact match for 'homer_simpson'");
ok(fuzm("homersimpson"), "still matches without the underscore");
ok(fuzm("homers_impson"), "putting the underscore in a different place, still matches");
ok(fuzm("ho_mer_simpson"), "an extra underscore still matches");
ok(fuzm("ho_mer_simp_son"), "2 extra underscores still matches");
ok((not fuzm "ho_mersimp_son"), "2 underscores, both in the wrong places, doesn't match");
ok((not fuzm "ho_mer_sim_ps_on"), "3 extra underscores doesn't match");
ok((not fuzm "homer____simpson"), "3 extra underscores doesn't match");
regex in Dreamweaver
The regular expression you seek is: [^"]* so if you want to change all these: <a class="wildcat" href="lion.html"> <a class="wildcat" href="tiger.html"> <a class="wildcat" href="leopard.html"> to: <a class="wildcat" href="bigcat.html"> you search for: <a class="wildcat" href="[^"]*"> and replace with: <a class="wildcat" href="bigcat.html"> (make sure you tick the match case & regular expressions + seclect 'source code')
Use a variable in a JavaScript regular expression
var baz = "foo"; var filter = new RegExp(baz + "d") "food fight".match(filter); // returns ["food"]
IBAN regex (all IBANs)
[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{4}[0-9]{7}([a-zA-Z0-9]?){0,16}
BIC (Bank Identifier Code) Regex
([a-zA-Z]{4}[a-zA-Z]{2}[a-zA-Z0-9]{2}([a-zA-Z0-9]{3})?)
preg_match('/<div id=["]{0,1}ad_content["]{0,1}>(.*?)</div>/s', $content['content_body'], $matches);
$content['content_body'] = $matches[1];
Validate E-mail Adress
/(w|[_.-])+@((w|-)+.)+w{2,4}+/