Johan
Johan

Reputation: 35194

Any number of whitespaces

My pattern: \s^SID\d{3,}$\s

I want to allow any number of leading and trailing whitespaces, but it doesn't seem to work. What did I miss?

Upvotes: 4

Views: 2411

Answers (2)

Jerry
Jerry

Reputation: 71538

The \s go after the beginning of line anchor and before the end of line anchor. After that, you need the * quantifier.

^\s*SID\d{3,}\s*$

Upvotes: 4

PP.
PP.

Reputation: 10864

If you want whitespace to ALWAYS be there then:

^\s+SID\d{3,}\s+$

If you want whitespace to be OPTIONAL then:

^\s*SID\d{3,}\s*$

Note that if you put a plus after anything it means "1 or more" whereas an asterisk means "zero or more".

Upvotes: 6

Related Questions