Regular expression syntax required


Badge +8

I need a syntax that pulls a string that may be up to 10 numbers or could also include characters.


4 replies

Badge +9

Hi Michelle Goodman‌,

Can you provide more details what you are trying to do?

Are you trying to limit the number of characters in a string? If so, Try with ^[A-Za-z0-9]{0,10}$ which allows you to limit the number of characters to 10. you can choose small/upper case and numbers.

Try to construct your regular expression in Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript  and use it.

Thanks,

Lakshmi Narayana C

Badge +9

^w{1,10}$

^ asserts position at start of the string
w{1,10}
matches any word character (equal to [a-zA-Z0-9_])
{1,10} Quantifier — Matches between 1 and 10 times, as many times as possible, giving back as needed (greedy)
$ asserts position at the end of the string, or before the line terminator right at
Badge +8

Hi Lakshmi

With ^[A-Za-z0-9]{0,10}$ will this pick up the text if it starts with numbers and then letters?

Thanks

Badge +9

Hi Michelle Goodman‌,

Yes it will allow either alphabets(small/upper) or numbers or mix up to 10 characters. If you want try in the Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript site before once.

Thanks,

Reply