I'm working on a website for a friend and I needed to chomp. So I worked out the regex.
Here you go.
Javascript:
EDIT: corrected!
// chomp
function chomp(text)
{
// Check for empty
if (text.search(/\S/) === -1)
{
return "";
}
else
{
// Chomp it.
return text.replace(/^\s*((\S+\s+)*?\S+)\s*$/, "$1");
}
}
8 August 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment