5

I thought to ask this as an update to my previous similar question but it became too long.

I was trying to understand a regex given in w3.org that matches css comments and got this doubt

Why do they use

\/\*[^*]*\*+([^/*][^*]*\*+)*\/
----------------^

instead of just

\/\*[^*]*\*+([^/][^*]*\*+)*\/

?

Both are working similarly. Why do they have an extra star there?

  1. Let's look at this part:

    \*+([^/*][^*]*\*+)*
    -A- --B--     -C-
    

    Regex engine will parse the A part and match all the stars until there is NO MORE stars or there is a line break. So once A is done, the next character must be a line break or anything else that's not a star. Then why instead of using [^/] they used [^/*]?

  2. Also look at the repeating capturing group.

    ([any one char that's not / or *][zero or more chars that's not *][one or more stars])

    It captures groups of characters ending with atleast one or more stars. So C will take all the stars leaving B with no stars to match in the next round.

    So the B part won't get a chance to meet any stars at all. That is why I think there's no need to put a star there.

But that regex is in w3.org so I guess my understanding may be wrong. Please explain what I'm missing.

0

1 Answer 1

4

This has already been corrected in the CSS3 Syntax module:

\/\*[^*]*\*+([^/][^*]*\*+)*\/   /* ignore comments */

Notice that the extraneous asterisk is gone, making this expression identical to what you have.

So it would seem that it was simply a mistake on their part while writing the grammar for CSS2. I'm digging the mailing list archives to see if there's any discussion there that could be relevant.

Sign up to request clarification or add additional context in comments.

5 Comments

OMG! So I was right (and late to find out.) I only thought that they must be right and exhausted my mind trying to find what I'm missing. I didn't think it would have been changed in CSS3. Thanks.
Yes. I am waiting for your link to any relevant discussion.
I can't seem to find anything :/
I just pasted the regex in their advanced search and found this only result: lists.w3.org/Archives/Public/public-mobileok-checker/2007Sep/… But I don't understand what they are talking. Okay thanks anyways.
@Vigneshwaran: That discussion is not related to the grammar itself, so you can ignore it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.