Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex match strings less than 150 chars in length

Tags:

regex

I've been having no luck with a simple regex to match strings with 150 or less characters to alert my users of descriptions being too short.

These description values can contain any character/number with no specific pattern. Can someone with regex knowledge lend a hand?

like image 520
James Mathieson Avatar asked Jun 02 '13 04:06

James Mathieson


People also ask

How do you restrict length in regex?

By combining the interval quantifier with the surrounding start- and end-of-string anchors, the regex will fail to match if the subject text's length falls outside the desired range.

What does '$' mean in regex?

$ means "Match the end of the string" (the position after the last character in the string). Both are called anchors and ensure that the entire string is matched instead of just a substring.


1 Answers

^.{0,150}$

This will match a whole string containing between 0 and 150 (inclusive) of any character. Though regular expressions are probably the wrong tool for this job.

like image 152
Cairnarvon Avatar answered Oct 06 '22 01:10

Cairnarvon