Jump to content

Recommended Posts

I'm kind of interested in how that really works for you when [...] signifies a character class, and

actually matches any one character of s,p,o,i,l,e, or r (same thing for the 2nd one, except that it also will match a forward slash).  Is it being run through preg_quote() first?

 

If that really works for you as is, you can do this:

 

([sp(?:oiler)?](.+?)[/sp(?:oiler)?])

 

The setting in which I'm using it in is actually a bit more complicated, but yea it does work for me:

 

$string = preg_replace_callback("(\[spoiler\](.+?)\[\/spoiler\])", create_function('$matches', 'return getContent("spoiler", Array(str_makerand(32, 32, true, false, true), $matches[1]));'), $string);

 

Similarly I'm using other things like this for other bbcode:

 

$string = preg_replace("(\[b\](.+?)\[\/b])is",'<span class="post-style-bold">$1</span>', $string); 
    $string = preg_replace("(\[i\](.+?)\[\/i\])is",'<span class="post-style-italic">$1</span>', $string);

 

However, what you gave me doesn't work. It matches a lot of things incorrectly.

What's wrong with what I gave you is that I did not escape the brackets because you did not escape them in your OP.

 

That's why I asked about the preg_quote and mentioned what it should be doing, since they weren't escaped.  That's why what you have works: you have the brackets escaped in the code you just now posted.  Kind of scratching my head about why you would post what you currently have, but remove the escapes?

 

(\[sp(?:oiler)?\](.+?)\[\/sp(?:oiler)?\])

That's really.. weird? I don't see how I could've removed them.. I c&p'd that directly from my file.

 

Sounds like you might have the same posting issue I'm having.. if I cut and paste code (say a regex pattern) from my IDE into the posting field, stuff like \d will become simply d (just hitting preview over and over again wipes out the backslash for me.. so I find myself needing to manually re-enter backslashes prior to hitting 'Post'.

CV, I'm using Netbeans (6.7).. in conjunction with XP (Service Pack 3), but this issue started cropping up a few weeks ago on this site (prior to that, everything was behaving fine). I wasn't sure if it was my system or not.. so when I tested posting samples on other website forums (like sitepoint), no issues at all. It's all in this site it seems.

 

I posted this issue in the Questions, Comments and Suggestions forum.. but seems non-replicatable. So I'm not sure why I am having the above issue (as well as having all my code as a long line within the php tags (seems like \r\n are ignored for some reason). I figured it might be a Chrome only thing, but while it is better in Firefox 3.0 / 3.5, I still have some of these issues in FF.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.