| |||
Views: 88,542,912 |
Main | FAQ | Uploader | IRC chat | Radio | Memberlist | Active users | Latest posts | Calendar | Stats | Online users | Search | 05-05-24 11:48 PM |
|
Guest: Register | Login |
0 users currently in Computing | 1 guest |
Main - Computing - Quick regex problem | New thread | New reply |
Kailieann |
| ||
Red Cheep-cheep Level: 34 Posts: 136/217 EXP: 253428 Next: 223 Since: 02-19-07 From: Beyond Last post: 5646 days Last view: 5646 days |
Okay. My regex skills are a little rusty, so forgive me if I'm overlooking something obvious here.
What I'm trying to do is create a regex pattern that will match text outside square brackets -- specifically, this is for PHP's preg_replace() function. The pattern I have so far is (^|\])(.*?)?(\[|$) The problem I'm having is that this pattern is matching the brackets as well as the text. Which, with that particular pattern, means it's working properly. What I need to know now is how do I make it so the brackets are required in order to make a match, but aren't returned as part of the match. Any help would be appreciated. |
Csaw |
| ||
Newcomer Banned for trolling until 7/12. Level: 3 Posts: 1/1 EXP: 79 Next: 49 Since: 03-25-07 Last post: 6251 days Last view: 6251 days |
// What you want to replace $replacements = array('[', ']'); // str_replace returns $string with [ and ] replaced by blanks, this is // then the string that is returned by preg_replace when $pattern is matched // within $string preg_replace($pattern, str_replace($replacements, '', $string), $string); |
Main - Computing - Quick regex problem | New thread | New reply |
© 2005-2023 Acmlm, blackhole89, Xkeeper et al. |
MySQL - queries: 42, rows: 52/53, time: 0.015 seconds. |