Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python regex for matching two or three white spaces

I'm trying to match the following text with a regex in Python 2.7

SUBCASE   8
SUBCASE   9
SUBCASE  10
SUBCASE  11

The number of spaces between "subcase" and the number drops from 3 to 2. I'm trying to use this regex in Python:

(SUBCASE)[\s+]([0-9]+)

Where am I going wrong? Shouldn't the \s+ mean "catch any white spaces more than one"?

like image 591
prrao Avatar asked Aug 06 '12 19:08

prrao


2 Answers

You'll want:

SUBCASE\s+([0-9]+)

or

SUBCASE\s+(\d+)

Putting \s+ inside of [...] means, that you want precisely one symbol that either is a whitespace character, or a plus.

like image 79
Sebastian Paaske Tørholm Avatar answered Sep 19 '22 02:09

Sebastian Paaske Tørholm


(SUBCASE)\s+([0-9]+) 

You used [\s+] which would do a character match of one whitespace or a + sign

like image 32
jassinm Avatar answered Sep 18 '22 02:09

jassinm