Script:
#!/usr/bin/env perl use strict; use warnings; use diagnostics; use feature 'say'; while (<DATA>) { chomp; if ($_ ne q{}) { s/Positive\sfor\s//; while (/ (?:and\s)? ((?:\w+\s)+) # Remember disease name \( ([^\)]+) # Remember list of family members \) /xg) { my ($disease, @persons) = ($1, map { s/^\s+//; s/\s+$//; $_; } split /;|,/, $2); $disease =~ s/\s$//; foreach my $person (@persons) { say "$person || $disease"; } } } } close DATA or die 'Could not close DATA: ', $!; __DATA__ Positive for Depression ( mother ; sister ), Type 2 Diabetes ( fat +her ; mother ; grandparents ) and Anxiety ( mother) . Cancer ( mother, grandmother )
Output:
mother || Depression sister || Depression father || Type 2 Diabetes mother || Type 2 Diabetes grandparents || Type 2 Diabetes mother || Anxiety mother || Cancer grandmother || Cancer
In reply to Re: Extracting multiple match and reorganizing order with Regex
by brilant_blue
in thread Extracting multiple match and reorganizing order with Regex
by NewMonk2Perl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |