RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Expressions by User

   Displaying page 1 of 1 pages; Items 1 to 4
Title Test Details Label all parts of a URL
Expression
(?:(?<protocol>http(?:s?)|ftp)(?:\:\/\/)) (?:(?<usrpwd>\w+\:\w+)(?:\@))? (?<domain>[^/\r\n\:]+)? (?<port>\:\d+)? (?<path>(?:\/.*)*\/)? (?<filename>.*?\.(?<ext>\w{2,4}))? (?<qrystr>\??(?:\w+\=[^\#]+)(?:\&?\w+\=\w+)*)* (?<bkmrk>\#.*)?
Description
I needed a regular expression to break urls into labled parts. This is what I came up with. Got a few ideas from regexlib.com and from this msdn article. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/reconbackreferences.asp http://www.domain.com/folder does return a match but will not grab the folder name unless there is &quot;/&quot; at the end. http://www.domain.com/folder/
Matches
https://192.168.0.2:80/users/~fname.lname/file.ext | ftp://user1:[email protected] | http://www.dom
Non-Matches
www.domain.com | user1:[email protected] | 192.168.0.2/folder/file.ext
Author Rating: The rating for this expression. Ariel Merrell
Title Test Details Validate 12hour clock
Expression
(?<Time>^(?:0?[1-9]:[0-5]|1(?=[012])\d:[0-5])\d(?:[ap]m)?)
Description
A co-worker needed a regex to validate time. He could only find patterns that match a 24hour clock. I whipped this expression up to validate a 12hour clock. Hope somebody finds it useful.
Matches
12:00am | 01:30pm | 4:59
Non-Matches
15:30 | 4:78am | 00:00
Author Rating: The rating for this expression. Ariel Merrell
Title Test Details Link Text and URL from anchor
Expression
<a.+?href\=(?<link>.+?)(?=[>\s]).*?>(?<lnkText>.+?)</a>
Description
Captures an html anchors URL and Link Text. Could be used to clean up formatting of links in an html document.
Matches
<a href=http://capturedLink target=blah>captured Text</a>|<a class="blah" href="http://capturedLink" target="blah">captured Text</a>
Non-Matches
Any other html tags
Author Rating: Not yet rated. Ariel Merrell
Title Test Details Capture Text between style tags
Expression
<style.*?>(?<StyledText>.*)<\s*?/\s*?style.*?>
Description
A blogger needed a regex to capture the text between style tags.
Matches
<style class="blah">Captures Me</style>
Non-Matches
Will not capture the style tag itself
Author Rating: Not yet rated. Ariel Merrell
   Displaying page 1 of 1 pages; Items 1 to 4

Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials