locked
^[\S\s]* Regular Expression meaning ?

    Question

  • Hello,

    What's the meaning of this regular expression  :

    ^[\S\s]*

    As far as I understand: \s means a whitespace character, \S Non-whitespace characters and [\S\s] means any character, anything. So, ^[\S\s] means Nothing, but i've tested it on various regex testers online and any character i entered was considered a match, how come ?

    I appreciate your help :) 

    Wednesday, January 04, 2012 12:13 PM

Answers

  • Hi,

    [\S\s] == any character

    ^ is "start of input (start of line if you use multiline option).

    So ^[\S\s]* matches the whole text

    ^([\S\s]{0,12})$ matches a line (or the whole text) if it's 12 characters long...

    ^ means "not" only inside brackets if it's the first element in the bracket..

    [^a] == not a

    [a^] == a or ^

    Greetings,

     


    Wolfgang Kluge
    gehirnwindung.de
    • Edited by WolfgangKluge Wednesday, January 04, 2012 2:36 PM
    • Marked as answer by SB User Thursday, January 05, 2012 12:46 PM
    Wednesday, January 04, 2012 2:34 PM

All replies

  • More clarification:

    This is the main regex i'm trying to understand:

    ^([\S\s]{0,12})$

     

     

     

     
     

    • Edited by SB User Wednesday, January 04, 2012 12:19 PM
    Wednesday, January 04, 2012 12:18 PM
  • Hi,

    [\S\s] == any character

    ^ is "start of input (start of line if you use multiline option).

    So ^[\S\s]* matches the whole text

    ^([\S\s]{0,12})$ matches a line (or the whole text) if it's 12 characters long...

    ^ means "not" only inside brackets if it's the first element in the bracket..

    [^a] == not a

    [a^] == a or ^

    Greetings,

     


    Wolfgang Kluge
    gehirnwindung.de
    • Edited by WolfgangKluge Wednesday, January 04, 2012 2:36 PM
    • Marked as answer by SB User Thursday, January 05, 2012 12:46 PM
    Wednesday, January 04, 2012 2:34 PM

  • That helped a lot. Thank you very much !

    Thursday, January 05, 2012 12:46 PM