regex - Perl regular expression question -


I want to use the Perl split function on comma-delimited lines and between the commas only an array of two or more words I want to be demoted in Single words are not required.

For example, this line - & gt; & Gt; (& Lt; FH & gt;) {@ = split (FLA) (ADA), AAA, CCC Deed, EEE, FFF, GUUUUUUUI, I only want, CCC Deed and FAF GGUUUUI

  /, /); }    

demo script:

  my @data = ('AAA, CCC Deed, EII, FFF GUUUU', 'AABBB, CCC, EEE, FFF GGUUU', 'AAA, CCC, EEE, FFF'); For my $ line (@dieta) {printf "|% s | ==> \ n", $ line; $ Line = ~ s / ^ \ s + | \ S + $ // g; My @ cut = grep {/>} partition (/ \ s *, \ s * /, $ line); Printf "|% s | \ n \ n", join ('|', @cut); }   

Output:

  | Aaa, ccc ddd, eee, fff ggg uuu | ==> | CCC DDF | FFF GGIUUUUI | | AAA BBB, CCC, EEE, FFF, GUUUUUUI. ==> | AAA BBB | FFF GGIUUUUI | | Aaa, CCC, EEE, FFF | ==> ||   

Less disturbances compared to Dahlahalen's solution, but can be easier to handle / handle special cases.

Comments