简体   繁体   English

用于匹配两个或三个空格的Python正则表达式

[英]Python regex for matching two or three white spaces

I'm trying to match the following text with a regex in Python 2.7 我试图将以下文本与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”和数字之间的空格数从3下降到2.我试图在Python中使用这个正则表达式:

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

Where am I going wrong? 我哪里错了? Shouldn't the \\s+ mean "catch any white spaces more than one"? 不应该\\s+意味着“抓住任何一个以上的空白区域”吗?

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. \\s+放在[...]意味着,您只需要一个符号,即空白字符或加号。

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

你使用了[\\ s +]来做一个空格或+符号的字符匹配

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM