Reputation: 257
Here is my regex:
^(SK{1}[0-9]{8})$
But I want text like this:
SK 283 92758
SK 283 92 7 58
to be taken as this:
SK28392758
It is possible?
Upvotes: 4
Views: 16767
Reputation: 1
If you want to remove any whitespaces use [^\s]
.
See the demo here: https://regex101.com/r/a1kojC/1
Upvotes: -1
Reputation: 424983
Use the "optional" quantifier ?
for a space between each character:
^S ?K ?(\d ?){7}\d$
This allows an optional space between the characters.
To allow any number of spaces, replace every ?
with *
.
See live demo.
I also removed unnecessary brackets:
{1}
is pointless0
, which is the whole match, is always available is you absolutely need a capture groupUpvotes: 2
Reputation: 7200
You can use the regex ^(SK{1}\s\d{3}\s\d{5})$
and use a String.Replace
afterwards to remove the spaces.
Upvotes: 0