Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex matching except whitespace in Python

Tags:

python

regex

I am looking to match on a white space followed by anything except whitespace [i.e. letters, punctuation] at the start of a line in Python. For example:

 ` a`  = True
 ` .` = True
 `  a`  = False    [double whitespace]
 `ab` = False      [no whitespace]

The rule re.match(" \w") works except with punctuation - how do i include that?

like image 614
kyrenia Avatar asked Dec 15 '22 11:12

kyrenia


1 Answers

Remember the following:

\s\S
  • \s is whitespace
  • \S is everything but whitespace
like image 72
psla Avatar answered Dec 31 '22 00:12

psla