Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any number of whitespaces

Tags:

regex

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?

like image 368
Johan Avatar asked Oct 19 '25 04:10

Johan


2 Answers

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".

like image 128
PP. Avatar answered Oct 21 '25 18:10

PP.


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*$
like image 39
Jerry Avatar answered Oct 21 '25 18:10

Jerry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!