homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

Regex for description

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

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)

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>";

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved