Log in

View Full Version : RegExp Question



JBottero
02-04-2009, 05:37 PM
Does this look like it will work? Is there a better way to do this?

$pattern = '/\{SomeString\s*[0-9a-fA-F\s]\}/';to match "Opening Curly Brace + SomeString + Space Char + Any Number of Letters and Numbers and Space Chars + Closing Curly Brace"

I would be using this with preg_replace.

Twey
02-04-2009, 07:02 PM
That's not 'any number of letters and numbers': it only covers hexadecimal digits (0-F). \s doesn't just match spaces: it matches any whitespace character, including tabs, vtabs, &c., and I think you've applied the * wrongly: modifiers go after the terms they modify.

You've got the right idea, though. Going by the description, something like '/\{SomeString [0-9a-zA-Z ]*\}/' would be ideal.