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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -