63 regular expressions found in this category!
Displaying page
of
pages;
Items to
| Title |
Test
Details
Quoted string
|
| Expression |
^(\x22|\x27)((?!\1).|\1{2})*\1$ |
| Description |
The regex validate a quoted string in VBScript or Ansi SQL. The string may contain the containing quote character if it is escaped by being doubled up.
In VB/VBScript two double quotes within a string enclosed in double qoutes translate into one double quote within the string
In SQL two single quotes within a string enclosed in single qoutes translate into one single quote within the string |
| Matches |
"To quote Yoda (""Do, or do not. There is no 'try'"" )" |
| Non-Matches |
'This won't validate' | "He said "Ok."" |
| Author |
Rating:
Michael Ash
|
| Title |
Test
Details
Pattern Title
|
| Expression |
^(Function|Sub)(\s+[\w]+)\([^\(\)]*\) |
| Description |
Updated, changed [\w]* to [\w]+ because pattern should not match Sub (), there would be no function name which would be incorrect.
Will extract function declarations from ASP or also VB I assume. Will even capture declarations that break across new lines or ones that use the underscore(line continuation character) in Microsoft's VB, VBA, ASP, etc. Had to put this together to document some code on a project and didn't see anything like it on the web. I hope it helps out anyone else who has to re-engineer ASP or VB code. |
| Matches |
Function MyFunc(Arg1, Arg2, Arg3, Arg4) |
| Non-Matches |
'This is a comment for MyFunc(Arg1,Arg2,Arg3) and this regexp wouldn't work. |
| Author |
Rating:
James Fal
|
| Title |
Test
Details
Pattern Title
|
| Expression |
&(?![a-zA-Z]{2,6};|#[0-9]{3};) |
| Description |
The goal of this regular expression is to replace all & (ampersand) characters by & if they are not the start of HTML entities. I used
http://www.w3schools.com/html/html_entitiesref.asp as a reference. You can then use RegExp Replace method to do the work. Was helpful for me, might helpful be for you... |
| Matches |
&ThisIsTooLong; | Lilo & Stich | &l; |
| Non-Matches |
< | ¦ | ¦ |
| Author |
Rating:
Frederick Samson
|
| Title |
Test
Details
(X)HTML click events
|
| Expression |
(?i:on(blur|c(hange|lick)|dblclick|focus|keypress|(key|mouse)(down|up)|(un)?load|mouse(move|o(ut|ver))|reset|s(elect|ubmit))) |
| Description |
This regex will match all the valid on event attributes in HTML 4.01/XHTML 1.0 |
| Matches |
onclick | onsubmit | onmouseover |
| Non-Matches |
click | onandon | mickeymouse |
| Author |
Rating:
Michael Ash
|
| Title |
Test
Details
Pattern Title
|
| Expression |
<(\/{0,1})img(.*?)(\/{0,1})\> |
| Description |
This regular expression allows you to match all image tags |
| Matches |
<img src="immy.jpg" alt="Image"> | <img src="immy.jpg" alt=&q |
| Non-Matches |
< img > |
| Author |
Rating:
Alessandro Pellegrini
|
| Title |
Test
Details
Enitity notation
|
| Expression |
&
(?ni:\# # if a pound sign follow ampsand look for number
((x # if x follow pound sign accept hex value up to 5 digits
([\dA-F]){1,5}
)
| # otherwise accept decimal number between 0 - 1048575
(104857[0-5]
|10485[0-6]\d
|1048[0-4]\d\d
|104[0-7]\d{3}
|10[0-3]\d{4}
|0?\d{1,6})
)
| # no pound sign after ampersand
([A-Za-z\d.]{2,31}) #accept ASCII alphanumeric and period
); #end with semi-colon. |
| Description |
This regex can be used to find general entites in HTML, XML and SGML files.
The entity can consist of
1) an ampsand (&)
2) followed by
(a) ASCII alphanumerics or period between 2 and 31 characters or
(b) a pound sign #
(i) followed by an x followed by a unicode value up to 5 hex digits or
(ii) followed by a decimal value from 0 to 1048575
3) ending with a semi-colon (;) |
| Matches |
"e; | © | ' |
| Non-Matches |
& | &#Hello; | &#Xray; |
| Author |
Rating:
Michael Ash
|
| Title |
Test
Details
Pattern Title
|
| Expression |
^[a-zA-Z_]{1}[a-zA-Z0-9_]+$ |
| Description |
This expression validates for valid C# or C++ identifier |
| Matches |
_12ffsd | abcd123 | abcd_23232 |
| Non-Matches |
..// | ..13e232 | abcd 3232 |
| Author |
Rating:
Ashish Sheth
|
| Title |
Test
Details
Pattern Title
|
| Expression |
<(?:[^"']+?|.+?(?:"|').*?(?:"|')?.*?)*?> |
| Description |
This will match all tags in a string, it's good for stripping HTML or XML tags to get the plain text.It works with attributes that include javascript or "<>".
It will match all these
<hr size="3"
noshade
color="#000000"
align="left">
<p style="margin-top:0px;margin-bottom:0px"
align="center"><font face="Times New Roman"
size="5"><b>UNITED STATES</b></font></p>
<input type=button onclick='if(n.value>5)do_this();'> not this <br> <input type=button onclick="n>5?a():b();" value=test> not this <br> <input type=button onclick="n>5?a(\"OK\"):b('Not Ok');" value=test> not this <br> <input type=button onclick='n>5' value=test onmouseover="n<5&&n>8" onmouseout='if(n>5)alert(\'True\');else alert("False")'> not this <br>
|
| Matches |
<input type=button onclick='n>5' value=test onmouseover="n<5&&n>8" onm |
| Non-Matches |
haven't found any exceptions yet |
| Author |
Rating:
Toby Henderson
|
| Title |
Test
Details
Pattern Title
|
| Expression |
\xA9 |
| Description |
Matches the copyright symbol (&copy;). Pretty simple, yet I dont think existed on RegExLib before. |
| Matches |
© |
| Non-Matches |
anything |
| Author |
Rating:
Roman Lukyanenko
|
| Title |
Test
Details
Pattern Title
|
| Expression |
<[a-zA-Z][^>]*\son\w+=(\w+|'[^']*'|"[^"]*")[^>]*> |
| Description |
Find HTML tags that have javascript events attached to them. |
| Matches |
<IMG onmouseover="window.close()"> |
| Non-Matches |
<IMG src="star.gif"> |
| Author |
Rating:
Lewis Moten
|
| Title |
Test
Details
Pattern Title
|
| Expression |
<[^>]*> |
| Description |
HTML Pattern Matching
PLEASE HELP
/<[^>]*>/ig
The above pattern is only successful when html tag are simple (they don't include any javascript). This mean that the pattern will fail if something like this is within the tag <input type=button value=test onclick='if(n.value>5)do_this();'>. It will not match the entire open n close sign.
How do you write a pattern that will pass all these tag so that the pattern will match from the open to the close sign and not when it just see a > within a '' or "".
<input type=button onclick='if(n.value>5)do_this();'> not this <br>
<input type=button onclick="n>5?a():b();" value=test> not this <br>
<input type=button onclick="n>5?a(\"OK\"):b('Not Ok');" value=test> not this <br>
<input type=button onclick='n>5' value=test onmouseover="n<5&&n>8" onmouseout='if(n>5)alert(\'True\');else alert("False")'> not this <br>
Any help would be greatly appreciate. Thanks a whole lot.
Logan |
| Matches |
<html> |
| Non-Matches |
abc |
| Author |
Rating:
Logan Tran
|
| Title |
Test
Details
Pattern Title
|
| Expression |
(?i:)(?<=\.)\D\D(?:-\D{2,3}?(?:-\D\D\D\D)?)?(?=.resx)
#Just change the extension if you want to take a Culture out of different type of file name.
#The result will always be of the format:
#(2CharacterLanguage)-(2or3CharacterLocale)-(4CharacterScript)
#where the second or third set are optional
#this matches the format of the CultureInfo object in Microsoft .NET |
| Description |
This expression pulls the Culture name out of a .resx file name. |
| Matches |
blah.is.en.resx | something.zh-CHS.resx | something.uz-UZ-Cyrl.resx |
| Non-Matches |
blah.is.eee.resx | something.zh-X.resx | something.uz-UZ-Uz.resx |
| Author |
Rating:
Eric Falsken
|
| Title |
Test
Details
Pattern Title
|
| Expression |
href[ ]*=[ ]*('|\")([^\"'])*('|\") |
| Description |
the regex's on this site for pulling links off a page always seemed to be faulty, or at least never worked with PHP, so i made this one. simple, as i'm an amateur with regex's, but stumbled thru it and this one actually works. tested with PHP function: preg_match_all("/href[ ]*=[ ]*('|\")([^\"'])*('|\")/",$string,$matches) |
| Matches |
href="index.php" | href = 'http://www.dailymedication.com' | href = "irc://irc.junk |
| Non-Matches |
href=http://www.dailymedication.com |
| Author |
Rating:
Jason Paschal
|
| Title |
Test
Details
Pattern Title
|
| Expression |
/\*[\d\D]*?\*/ |
| Description |
If you need to extract or remove any /* */ sytle comments from any Java, JavaScript, C, C++, CSS, etc code you have this regular expression can help. |
| Matches |
/* my comment */ | /* my multiline comment */ | /* my nested comment */ |
| Non-Matches |
*/ anything here /* | anything between 2 seperate comments | \* *\ |
| Author |
Rating:
Chris Craft
|
| Title |
Test
Details
Pattern Title
|
| Expression |
^#?([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?$ |
| Description |
Tests for valid HTML hexadecimal color codes. The # symbol is optional. And it will except either the 3 digit form for the 216 Web safe colors, or the full 6 digit form. I am use it on my site to allow users to customize the site's colors. |
| Matches |
#00ccff | #039 | ffffcc |
| Non-Matches |
blue | 0x000000 | #ff000 |
| Author |
Rating:
Chris Craft
|
| Title |
Test
Details
Pattern Title
|
| Expression |
src[^>]*[^/].(?:jpg|bmp|gif)(?:\"|\') |
| Description |
This expression will return the src (source) property of an image tag <IMG>. The source returned is limited to the file extensions supplied. It doesn't matter if the image is prefixed with '../' or 'http://..blah' or 'drive\path' or nothing. This expression could be modifed to return other sources or for the tags (ie <BGSOUND>, <SCRIPT>, etc.) depending on the file extensions given.
I needed this to replace the source of images in a HTML page when I wanted to save the page to a local drive and keep the images intact.
If anybody could modify this further to include only the <IMG> tag, I would appreciate the effort. |
| Matches |
src="../images/image.jpg" | src="http://domain.com/images/image.jpg" | src='d:\w |
| Non-Matches |
src="../images/image.tif" | src="cid:value" |
| Author |
Rating:
Lloyd Sturge
|
| Title |
Test
Details
Pattern Title
|
| Expression |
<!--[\s\S]*?--> |
| Description |
Removes pesky comments and commented javascript from HTML |
| Matches |
<!-- comments --> | <!-- x = a > b - 3 --> |
| Non-Matches |
<COMMENTS>this is a comment</COMMENTS> |
| Author |
Rating:
Lewis Moten
|
| Title |
Test
Details
Pattern Title
|
| Expression |
>(?:(?<t>[^<]*)) |
| Description |
Detects HTML tags open and/or closed with and without whitespace or characters in between. Good for stripping all tags from a string. |
| Matches |
<b> | </b> | <p><b>some text</b></p> |
| Non-Matches |
< |
| Author |
Rating:
Jonathan Crossland
|
| Title |
Test
Details
Pattern Title
|
| Expression |
^(#){1}([a-fA-F0-9]){6}$ |
| Description |
Matches HTML Color strings. Like #FFFFFF is white and #000000 is black and #FF0000 is red and so on... |
| Matches |
#FFFFFF | #FF3421 | #00FF00 |
| Non-Matches |
232323 | f#fddee | #fd2 |
| Author |
Rating:
Mladen Mihajlovic
|
| Title |
Test
Details
Pattern Title
|
| Expression |
^\s*-?(\d*\.)?([0-2])?[0-9]:([0-5])?[0-9]:([0-5])?[0-9](\.[0-9]{1,7})?\s*$ |
| Description |
This should be the pattern described in the documentation for the .NET TimeSpan.Parse method - generally parses time spans.
From the .NET docs:
public static TimeSpan Parse(string s);
The s parameter contains a specification of the form:
[ws][-][d.]hh:mm:ss[.ff][ws]
Items in square brackets ([ and ]) are optional, colons and periods (: and .) are literal characters, and other items are as follows.
Item Description
ws optional white space
"-" optional minus sign indicating a negative time
"d" optional days
"hh" hours, ranging from 0 to 23
"mm" minutes, ranging from 0 to 59
"ss" seconds, ranging from 0 to 59
"ff" optional fractional seconds, from 1 to 7 decimal digits
|
| Matches |
10:12:34 | 932323.9:00:32.3420 |
| Non-Matches |
10:20:80 |
| Author |
Rating:
Philipp Schumann
|
Displaying page
of
pages;
Items to