Tag Archive for Expression

Regular Expression, getting all parts of a E-Mail Date Header field

'~(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?~'

source

Use a variable in a JavaScript regular expression

var baz = "foo";

var filter = new RegExp(baz + "d")

"food fight".match(filter);

// returns ["food"]

source

preg_match('/<div id=["]{0,1}ad_content["]{0,1}>(.*?)</div>/s', $content['content_body'], $matches);
$content['content_body'] = $matches[1];

source

Remove URLs from String

$string = preg_replace('/(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|$!:,.;]*[A-Z0-9+&@#/%=~_|$]/i', '', $string);

source

preg_match for Hexadecimal Strings

function isHexadecimalString ( $str ) {
if ( preg_match("/^[a-f0-9]{1,}$/is", $str) ) {
return true;
} else {
return false;
}
}

source

width expression

#gl-wrapper{
zoom:1;
width:expression((document.compatMode && document.compatMode == 'CSS1Compat') ? (document.documentElement.clientWidth < 950 ? "950px" : (document.documentElement.clientWidth > 1280 ? "1280px" : 'auto')) : (document.body.clientWidth < 950 ? "950px" : (document.body.clientWidth > 1280 ? "1280px" : 'auto')));
}

source

Sterling Job Search

{doctype}
<head>
{embed="site/_global_head_title"}
{css}
</head>

<body class="home">

<div id="container">

<div id="content">
<div id="content-main">
<form name="frm_jobsearch" method="get" action="">
<table border="0" cellspacing="0" cellpadding="4">
<tr>
<td class="arialsm">Specialty</td>
<td>
<select name="specialty" class="arialsm">
<option value="Any">Any</option>

<option value="Emergency Medicine">Emergency Medicine</option>
</select></td>
</tr>
<tr>
<td class="arialsm">Profession</td>
<td>
<select name="profession" class="arialsm">
<option value="Any">Any</option>

<option value="Doctor of Osteopathy">Doctor of Osteopathy</option>

<option value="Medical Doctor">Medical Doctor</option>

<option value="Nurse Practitioner">Nurse Practitioner</option>

<option value="Physician Assistant">Physician's Assistant</option>
</select></td>
</tr>
<tr>
<td class="arialsm">State</td>
<td>
<select name="state" class="arialsm">
<option value="Any">Any</option>

<option value="Alabama">Alabama</option>

<option value="Arkansas">Arkansas</option>

<option value="Florida">Florida</option>

<option value="Georgia">Georgia</option>

<option value="Illinois">Illinois</option>

<option value="Louisiana">Louisiana</option>

<option value="Michigan">Michigan</option>

<option value="Ohio">Ohio</option>

<option value="Tennessee">Tennessee</option>

<option value="Virginia">Virginia</option>

<option value="Washington">Washington</option>
</select></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Search" class="arialsm" /></td>
</tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr>
<td>&nbsp;</td>
<td><a href="/jobs?specialty=&profession=&state=">View all jobs</a></td>
</tr>
</table>
</form>

<?php
if($_GET['specialty'] == "Any")
{
$specialty = 'Emergency Medicine';
} else {
$specialty = $_GET['specialty'];
}

if($_GET['profession'] == "Any")
{
$profession = 'Medical Doctor|Doctor of Osteopathy|Nurse Practitioner';
} else {
$profession = $_GET['profession'];
}

if($_GET['state'] == "Any")
{
$state = 'Florida|Alabama|Michigan';
} else {
$state = $_GET['state'];
}

?>

{exp:weblog:entries weblog="jobs" limit="25" rdf="off" dynamic="off" disable="categories|member_data|pagination|trackbacks" search:specialty="<?= $specialty ?>" search:profession="<?= $profession?>" search:state="<?= $state?>"}
<div class="item">
<ol>
<li>{title}</li>
<li>{description}</li>
<li>{specialty}</li>
<li>{profession}</li>
<li>{state}</li>
</ol>
<div>
{/exp:weblog:entries}

</div> <!-- close #content-main -->

</div> <!-- close #content -->

</div> <!-- close #container -->

</body>

</html>

source

OnKeyUp fix alphanumerical chars

<input type='text' onkeyup="this.value = this.value.replace(/[^a-z0-9]/gi,"");" />

source

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 &lt; and &gt;
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:
&lt;SPAN id=google-navclient-hilite style=&quot;COLOR:.#; BACKGROUND-COLOR:.#&quot;&gt;{.#}&lt;/SPAN&gt;

replace with:
1

source

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

source