I have a problem with regular expression and I'd like you to tell me what you think about it.
It's about custom bbcode. As you know there is no way to add your own bbcodes via ACP in phpBB2, but there is a way to do this by editing includes/bbcode.php and tempaltes/your_template/bbcode.tpl files.
So, I'm using bbcodes created by myself for quite a long time, but there is a "bug" in one of them...
This bbcode is simply colled "toggled code" - code which is hidden by default and when you click "show" button it's toggling down and you see all text inside it. The only difference is that hyper links in toggled code are clickable by default.
As it's very similiar to normal "code" bbcode it is also very similiar from coding side, so its function also return $text variable at the end and this variables goes through "function make_clickable($text)" in includes/bbcode.php file and here is the issue...
The problem is that the script doesn't parse http link located in first line of "toggled code" bbcode as clicable.
This is some lines from make_clickable function which is parsing the links, but as you can notice there need to be new line or space before http link to make it clickable:
- Code: Select all
// matches an "xxxx://yyyy" URL at the start of a line, or after a space.
// xxxx can only be alpha characters.
// yyyy is anything up to the first space, newline, comma, double quote or <
$ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);
Take a look just at first group, because there is an solution to get this to work! I was trying to add "]" (square bracket) to the range, but this didn't work.
Why? Because the string in posts_text table in database (this is from where script is taking the entire post body to parse through bbcode regexes) looks like:
- Code: Select all
[tcode:1:05c769fb0a]http
so adding "]" to the first group like that:
- Code: Select all
(^|[\]\n ])
should work, but it didn't - I don't know why. I was trying many many different ways, but neither worked and I found a mod to add ed2k link to phpbb2 (HERE) and got a part from its code to my bbcode.php like:
- Code: Select all
$ret = preg_replace("#(^|(?<=[^\w\"']))
and it is actually working !!
But....here is my question:
I'm using regex in VB .NET and know how to build a match, but I can not understand this regex structure, because "^" matches the begining of the string, but "^|" - what is it? "begining or.." I simlpy don't get this...
and the thing I copied from ed2k mod: "?<=" is positive lookbehind and matches a group before your main expression without including it in the result - i use this quite often, but then it matches the range of any word character, the double and single quote - without " or ' it won't match the string, but there is no quotes in my string, so why it's needed for is this range?
OK, but please tell me if the regex like this is safe and won't mess up other things in phpbb post parsing structure? As for now I haven't noticed any messed up other links and it works properly...so, what do you think ppl?
Thanks in advance for your replies.

English |
French
