Michdd Posted July 15, 2009 Share Posted July 15, 2009 I currently use this regular expression: (\[spoiler\](.+?)\[\/spoiler\]) which works for , but I want to edit it so it also works for [sp][/sp]. Quote Link to comment https://forums.phpfreaks.com/topic/165996-solved-little-help-changing-this-regex/ Share on other sites More sharing options...
.josh Posted July 15, 2009 Share Posted July 15, 2009 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)?]) Quote Link to comment https://forums.phpfreaks.com/topic/165996-solved-little-help-changing-this-regex/#findComment-875495 Share on other sites More sharing options...
Michdd Posted July 15, 2009 Author Share Posted July 15, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/165996-solved-little-help-changing-this-regex/#findComment-875499 Share on other sites More sharing options...
.josh Posted July 15, 2009 Share Posted July 15, 2009 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)?\]) Quote Link to comment https://forums.phpfreaks.com/topic/165996-solved-little-help-changing-this-regex/#findComment-875510 Share on other sites More sharing options...
Michdd Posted July 15, 2009 Author Share Posted July 15, 2009 That's really.. weird? I don't see how I could've removed them.. I c&p'd that directly from my file. Quote Link to comment https://forums.phpfreaks.com/topic/165996-solved-little-help-changing-this-regex/#findComment-875512 Share on other sites More sharing options...
.josh Posted July 15, 2009 Share Posted July 15, 2009 lol uh...hmm that is kinda weird. I've never heard of that happening before. Quote Link to comment https://forums.phpfreaks.com/topic/165996-solved-little-help-changing-this-regex/#findComment-875516 Share on other sites More sharing options...
nrg_alpha Posted July 15, 2009 Share Posted July 15, 2009 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'. Quote Link to comment https://forums.phpfreaks.com/topic/165996-solved-little-help-changing-this-regex/#findComment-875517 Share on other sites More sharing options...
.josh Posted July 15, 2009 Share Posted July 15, 2009 weird...that's never happened to me before, and I post regex patterns fairly often, same as you, nrg. What IDE do you use? I'm on vista using html-kit. Quote Link to comment https://forums.phpfreaks.com/topic/165996-solved-little-help-changing-this-regex/#findComment-875518 Share on other sites More sharing options...
nrg_alpha Posted July 15, 2009 Share Posted July 15, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/165996-solved-little-help-changing-this-regex/#findComment-875521 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.