Alright, I was able to fix my regex and it's working exactly as I want it to! Thank you! I was wondering if I could ask another question, though.
So now that I have my regex matching over multiple lines, I wanted to take the raw textfile and have the output be the entire paragraph bracketed in paragraph tags and the individual sentences inside with sentence tags. I was able to write the code to do both separately, with the necessary regex, but I need to write it so they're nested within each other.
Here's the code I have so far:
local $/ = ""; open $fh, $ARGV[0] or die "File $ARGV[0] not found!\n"; $scount = 0; $pcount=0; while ($line = <$fh>){ #brackets sentences while($line =~ /\s*(([A-Z][A-Za-z]*)(((([A-Za-z]|[0-9])*((\'*|\-*) +[A-Za-z]*))\s*(\.{3})*\!*\"*\(*\)*\,*\:*\s*)*(([A-Za-z]|[0-9])*))(\.| +\?|\!))/g){ print "<s>$1</s>\n"; $scount++; } #brackets paragraphs if ($line =~ /\s*((((([A-Za-z]|[0-9])*((\'*|\-*)[A-Za-z]*))\s*\.*\ +!*\"*\(*\)*\,*\:*\s*)*(([A-Za-z]|[0-9])*))(\.|\?|\!))/g){ print "<p>\n$1\n</p>\n"; $pcount++; } } print "\n Total Lines: $scount\n"; print "\n Total Paragraphs: $pcount\n";
When I run both sections at the same time, first it will print out each paragraph section with the sentence tags around each sentence, then it prints the same paragraph but with the paragraph tags. How do I fix it?
In reply to Re^2: How to match regex over multiline file
by kyaloupe
in thread How to match regex over multiline file
by kyaloupe
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |