Python regex for matching two or three spaces

I am 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 the “subheadings” and the number drops from 3 to 2. I am trying to use this regex in Python:

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

Where am I mistaken? Should it \s+mean "catch any spaces more than one"?

+5
source share
2 answers

Do you want to:

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

or

SUBCASE\s+(\d+)

Entering \s+inside [...]means that you want exactly one character, which is either a space character or a plus.

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

You used [\ s +] to match a single space character or +

+1
source

All Articles