'~(s?(?P<weekday>Mon|Tue|Wed|Thu|Fri|Sat|Sun))[,]?s?(?P<day>[0-9]{1,2})s(?P<month>Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)s(?P<year>[0-9]{4})s(?P<hours>[0-9]{2}):(?P<minutes>[0-9]{2})(:(?P<seconds>[0-9]{2}))?s(?P<timezone>[+|-][0-9]{4})s?~'
Tag Archive for regular
Regular Expression, getting all parts of a E-Mail Date Header field
Use a variable in a JavaScript regular expression
var baz = "foo"; var filter = new RegExp(baz + "d") "food fight".match(filter); // returns ["food"]
preg_match('/<div id=["]{0,1}ad_content["]{0,1}>(.*?)</div>/s', $content['content_body'], $matches);
$content['content_body'] = $matches[1];
Remove URLs from String
$string = preg_replace('/(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|$!:,.;]*[A-Z0-9+&@#/%=~_|$]/i', '', $string);
URL Validation via RegExp
var url:String = "http://www.google.com"; var regex:RegExp = /^http(s)?://((d+.d+.d+.d+)|(([w-]+.)+([a-z,A-Z][w-]*)))(:[1-9][0-9]*)?(/([w-./:%+@&=]+[w- ./?:%+@&=]*)?)?(#(.*))?$/i; trace(regex.test(url)); // returns true if valid url is found
preg_match for Hexadecimal Strings
function isHexadecimalString ( $str ) {
if ( preg_match("/^[a-f0-9]{1,}$/is", $str) ) {
return true;
} else {
return false;
}
}
OnKeyUp fix alphanumerical chars
<input type='text' onkeyup="this.value = this.value.replace(/[^a-z0-9]/gi,"");" />
hilite junk.
/*
Replace this:
<SPAN id=google-navclient-hilite style="COLOR: black; BACKGROUND-COLOR: cyan">Word</SPAN>
with this:
Word
Notes:
The chars '<'>' obviously appear in the html code as < and >
The minimal or lazy search operator used in Visual Studio is '#' which is roughly equivalent to '+?' in other RegEx syntax.
{...} is the tagged expression to be replace - again, Visual Studio syntax.
Test vectors used (snipplr stripped the complete SPAN markup):
<SPAN>file</SPAN> (expect file)
<SPAN>file</SPAN> (expect file)
<SPAN>file</SPAN> (expect file)
<SPAN>aaa</SPAN> (expect aaa)
<SPAN>file</SPAN><SPAN>file</SPAN> (expect filefile)
<SPAN>file aaa</SPAN> (expect file aaa)
(Visual Studio 2008 syntax)
*/
find:
<SPAN id=google-navclient-hilite style="COLOR:.#; BACKGROUND-COLOR:.#">{.#}</SPAN>
replace with:
1
Asp ereg_replace function (similar to php function)
function ereg_replace(pattern,change,str) Dim ObjRegexp Set ObjRegexp = New RegExp ObjRegexp.Global = True ObjRegexp.IgnoreCase = True ObjRegexp.Pattern = pattern str = ObjRegexp.Replace(str,change) Set ObjRegexp = Nothing ereg_replace = str end Function
Use Regular Expressions in Proc SQL
data test ;
length period $ 7 ;
input period ;
cards ;
2005
2005Q1
2005JAN
;;
run ;
proc sql;
create table qtrs as
select *
from test
where prxmatch("/dddd[qQ][1-4]/",period) ;
quit;
proc print data=qtrs ;
run ;