Question

this is my Regular expression.

^AK[0-9A-Za-z-/#\s]{1,15}$

It matches the whole string when we enter some text which starts like'AKtest123'

but i want to match the below strings like

A
AK
AKtest

how can i modify the regex to match the string from the first character?

Était-ce utile?

La solution

This should do the magic:

^(A|AK[0-9A-Za-z-/#\s]{0,15})$

That means it will accept A, or AK (notice I changed 1 at the end to 0), or AK and any following 15 characters from the list. Is that what you want, right?

Autres conseils

Maybe you're looking for something like this?

^A(?:K(?:[0-9A-Za-z-/#\s]{1,15})?)?$

It will match:

A
AK
AKtest

I think you need groups.

Change your regex to:

^(((A)K)[0-9A-Za-z-/#\s]{1,15})$

Group1 will have A, Group2 will have AK and Group3 will have AKtest

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top