Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Regex for description



6:54 pm on Dec 7, 2010 (gmt 0)

10+ Year Member

Hey guys, I need a good regex for a 100-3000 char description. I don't want to allow html tags but DO want to allow blanc lines. I always use ($Desc !~ m/^[^<\x09\x0a\x0d]{100,3000}\Z/) but that regex doesn't allow blanc lines.

Any Regex wizzard out there?




5:49 pm on Dec 9, 2010 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Well if you don't allow HTML, I would use ~= s/// to strip out the HTML, then just check the string length with length(), no regex needed for that.

# "Find a < or </ followed by anything
# NOT a > and sub it with NOTHING."
$string =~ # store the results in $string:
s/ # substitute
< # A beginning tag carat alone or . . .
\/* # next to a closing slash if there is one (*)
([^>])+ # Followed by one or more of anything NOT a >.
> # Followed by end of tag.
//igx; # sub with nothing, case-insensitive, global, allow whitspace in regex.

# in one line:
$string =~ s/ < \/* ([^>])+ > //igx;

if ((length($string) < 100) or ($length($string) > 3000)) {
print "<p>String is too long or too short.</p>";


Featured Threads

Hot Threads This Week

Hot Threads This Month