PDA

View Full Version : Small Javascript Help



acemaster
10-21-2008, 02:24 AM
I have created my own forum and am doing the bbcode by hand. I am allowing for users to preview their messages before they post them on the message board, only the following line doesn't convert. It works perfectly when processed through my PHP code, I'm guessing it has something to do with the ([^]]) part. I want to allow anything but a closing bracket, so everything after the equal sign and before a closing bracket is included as a URL. This is just for the user to preview it, so I'm not too worried about possible security vulnerabilities.


body = body.replace(/\[url\=([^]])\](.*?)\[\/url\]/g, "<a href='$1'>$2</a>");

acemaster
10-24-2008, 05:45 PM
Anyone got any suggestions on a better way to search for URL's?

acemaster
10-27-2008, 12:11 AM
For those that have tried, I found a solution



body = body.replace(/\[url=([^\]]*)\]([^\[]*)\[\/url\]/ig, '<a href="$1">$2</a>');