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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
(\[(\w+)\s*(([\w]*)=('|")?([a-zA-Z0-9|:|\/|=|-|.|\?|&]*)(\5)?)*\])([a-zA-Z0-9|:|\/|=|-|.|\?|&|\s]+)(\[\/\2\])
Description
Peseudo-HTML code matcher. Allows for one parameter within the first tag (name is optional), the value of which can be optionally delimited by either double or single quotes. Uses backreferencing to ensure that the end and start tags match, and that any single or double quotes match. Very useful for web forums or any situation where users may be prompted to enter text for display on a webpage somewhere, as it can be quickly processed into HTML without allowing HTML to be specified within the input itself (which may pose a security risk).
Matches
[link url="http://www.domain.com/file.extension?getvar=value&secondvar=value"]Link[/li
Non-Matches
[a]whatever[/b] | [a var1=something var2=somethingelse]whatever[/a] | [a]whatever[a]
Author Rating: Not yet rated. Simon Christensen
Source
Your Rating
Bad Good

Enter New Comment

Title
 
Name
 
Comment
 
Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: An issue resolved
Name: Michael Dumas
Date: 12/31/2008 8:50:44 AM
Comment:
(\[(\w+)\s*(([\w]*)=('|")?([a-zA-Z0-9|:|\/|=|-|.|\?|&]*)(\5)?)*\])(.*?)(?!<(\[\/\2\]))(\[\/\2\])


Title: An Issue...
Name: Will Graham
Date: 12/24/2008 9:30:34 PM
Comment:
I'm having an issue with nested tags. For example: [b][i]italic AND bold [/i][/b] Does not validate (I only get italic) If I knew ANYTHING about RegEx I would figure it out for myself, but I don't


Title: An Issue...
Name: Will Graham
Date: 12/24/2008 9:30:26 PM
Comment:
I'm having an issue with nested tags. For example: [b][i]italic AND bold [/i][/b] Does not validate (I only get italic) If I knew ANYTHING about RegEx I would figure it out for myself, but I don't


Title: my favorite RE
Name: SaberRider
Date: 12/15/2004 4:00:00 AM
Comment:
Great thing! Thanks! But the sample match may confuse. The closing Tag is [/li It should be [/link]


Title: COOL!
Name: Jonah Stagner
Date: 10/8/2004 6:47:40 PM
Comment:
Thank you for posting this, it is almost exactly what I have been looking for for some time now. My only complaint is that it doesn't allow tags like [link url="mailto:name@company.com"]name@company.com[/link]. Obviously, this wouldn't be a problem if I knew more about regex ;) Otherwise, quite nice and very useful.


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