Question

Can Anyone help me understand what the below pattern means:

/^([a-zA-Z0-9]){1}([a-zA-Z0-9\-\._]){0,27}\.([a-zA-Z]){1}([a-zA-Z0-9]){1,3}/

What a string must have so that it bounds to the above pattern.

These preg_match patterns are so confusing to understand. ! We are using it to see that a filename conforms to above pattern.

Regards, Sagar

Was it helpful?

Solution

Basically, you are matching filenames that start with a letter or digit, followed by the characters letter, digit, -, ., _, any number of times up to 27, even 0 times. Then, there is a ., probably separating the extension, which is composed of a letter followed by the characters letter, digit any number of times from 1 to 3.

Some examples:

a.aa, 0_.A0a, A---____-_.a999

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top