in reply to regexp question

Because having a character inside the character class that matches every but a newline doesn't make much sense. What would be the advantage of using /[.]/ over /./ if a dot meant the same thing inside a character class as outside it?

Replies are listed 'Best First'.
Re^2: regexp question
by ramprasad27 (Sexton) on Oct 28, 2011 at 08:58 UTC
    I would ask you the same question whats advantage in this case /[\d\s]/; meaning doesnt change outside of cc
      Of course it's different.
      [\d\s] # matches a single char - digit or whitespace \d\s # matches two chars - a digit then whitespace
      Because one can use \d and \s to build larger character classes. A dot already matches everything but a single character.

      What's the point of having such a character inside a character class? All you can do is build 4 different character classes: /[.]/, /[.\n]/, /[^.]/, /[^.\n]/. But they can all be written in a simple, different way: /./, /(?s:.)/, /\n/, and /(*FAIL)/

      So, once again, what would be the advantage of having dot inside a character class mean the same thing as outside of it?

        A dot already matches everything but a single character.

        Err... are you sure you meant to say that?