Page 1 of 1
string length regular expression
Posted: Fri Sep 14, 2007 1:38 pm
by kendall
Hi guys,
can you use preg_match() to test for a string length instead of using the strlength()
Posted: Fri Sep 14, 2007 1:48 pm
by Zoxive
Yes, but
str_len would be alot faster.
Posted: Fri Sep 14, 2007 1:55 pm
by kendall
Zoxive wrote:Yes, but
str_len would be alot faster.
was hoping to get a pattern example...i knew that already...

Posted: Fri Sep 14, 2007 1:58 pm
by Zoxive
kendall wrote:Zoxive wrote:Yes, but
str_len would be alot faster.
was hoping to get a pattern example...i knew that already...

I only answered your question as asked.
"Word Character" up to 10 characters long.
Posted: Fri Sep 14, 2007 3:40 pm
by GeertDD
Code: Select all
// for educational purposes only
preg_match('/^.{5}$/sD', 'abcde');
Since a string can contain any character, not just word characters, use the dot metacharacter. Also apply the s modifier to make the dot match newlines as well.
Posted: Fri Sep 14, 2007 3:51 pm
by kendall
GeertDD wrote:Code: Select all
// for educational purposes only
preg_match('/^.{5}$/sD', 'abcde');
Since a string can contain any character, not just word characters, use the dot metacharacter. Also apply the s modifier to make the dot match newlines as well.
hmmmm....neat!
Posted: Fri Sep 14, 2007 3:55 pm
by s.dot
This has just been bugging me... and it's not an answer to the original post... but maybe it's because I'm a stickler.
The function is
strlen(). Not str_len() or strlength().

Posted: Fri Sep 14, 2007 4:02 pm
by kendall
hahahah....duly noted scottayy dude