regex - Generate an abbreviation from a string in perl using regular expressions -
i'm new perl... want read file in perl. every time find 2 or more capitalized consecutive words, how can abbreviate them using regular expression? example,
" precursor graphical user interface invented researchers @ stanford research institute, led douglas engelbart. developed use of text-based hyperlinks manipulated mouse on line system ." wiki
the result : " precursor gui invented researchers @ sri , led de. developed use of text-based hyperlinks manipulated mouse ols ."
could done in single pass expression like:
s/\b([a-z])[a-z]+(?=\s+[a-z][a-z])|\g(?!^)\s+([a-z])[a-z]+/$1$2/g;
example:
$_ = "a precursor graphical user interface invented researchers @ stanford research institute, led douglas engelbart. developed use of text-based hyperlinks manipulated mouse on line system ."; s/\b([a-z])[a-z]+(?=\s+[a-z][a-z])|\g(?!^)\s+([a-z])[a-z]+/$1$2/g; print;
output:
a precursor gui invented researchers @ sri, led de. developed use of text-based hyperlinks manipulated mouse ols .
Comments
Post a Comment