November 23rd, 2008, 07:44 PM
Those Tricky Stars!
Ok, I figured out the strings myself, but I don't understand why my solution doesn't work for comments...
I am trying to detect /* whatever */
Here is my regular expression...
... I would expect that regular expression to work, but it doesn't...
This regular expression behaves as expected, but not as desired:
Why won't the first regular expression match? What can I do to make it match?
November 24th, 2008, 01:12 AM
That is because character classes always match a single character.
So the class [^(\*/)] will match any character except '(', '*', '/' or ')'. As you see, the "normal" meta characters like '(' and ')' don't group characters inside a character class as they do outside a character class. Also, the '*' does not need escaping inside a character class and it just matches the character '*'.
All of that said, you can match comments like this:
Last edited by prometheuzz; November 24th, 2008 at 01:14 AM.