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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
(\[[Ii][Mm][Gg]\])(\S+?)(\[\/[Ii][Mm][Gg]\])
Description
easy when you want to allow your users to post images, but in a controlled way. I used it like this (in php): $text = preg_replace("/(\[IMG\])(\S+?)(\[\/IMG\])/is", "<a href=\"\\2\" target=\"_blank\"><IMG SRC=\"\\2\" align=\"center\" height=\"100\" border=\"0\"></a>",$text); so whenever they use [img]http://www.foo.com/bleh.jpg[/img] it will be converted to <a href="http://www.foo.com/bleh.jpg" target="_blank"><IMG SRC="http://www.foo.com/bleh.jpg" align="center" height="100" border="0"></a> so you get a 100 pixels high picture, and when they click on it it opens in a new window... (to prevent users from posting huge pictures and stuff)
Matches
[IMG]http://bleh.jpg[/IMG] | [ImG]bleh[/imG] | [img]ftp://login:[email protected][/img]
Non-Matches
<img src="bleh.jpg">
Author Rating: The rating for this expression. marnik vander elst
Source #php.uk on Quakenet (irc.quakenet.org)
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: I've got a question
Name: Christoph
Date: 8/5/2004 8:04:48 AM
Comment:
I can't become clever. Why do you put the ? after the +. Whatfor? Greets


Title: wauw
Name: bert verbeek
Date: 2/2/2004 3:57:46 AM
Comment:
wauw man, this is great, it's what i've been looking for for the past few years. You r0x0r my b0x0r!


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