2021-03-30

Making Regex combination of multiple chars and numbers combined

How to write a regex that will combine numbers and chars in a string in any order? For example, If I want to read some kind of invoice number, I have example like this:

example 1: 32ah3af
example 2: 32ahPP-A2ah3af
example 3: 3A63af-3HHx3B-APe5y5-9OPiis
example 4: 3A63af 3HHx3B APe5y5 9OPiis

So each 'block' have length between 3 and 7 chars (letters or numbers) that can be in any order (letters can be lowercase or uppercase). Each. 'block' can start with letter or with number. It can have one "block" or max 4 blocks that are separated with ' ' or -.

I know that I can make separators like: \s or \-, but I have no idea how to make these kind of blocks that have (or do not have) separator.

I tried with something like this:

([0-9]?[A-z]?){3,7}

But it does not work



from Recent Questions - Stack Overflow https://ift.tt/3cyQtwv
https://ift.tt/eA8V8J

No comments:

Post a Comment