note
mr_ron
<p><blockquote>
Are you sure you want a match, and that you can only use a single regex? <a href="https://en.wikipedia.org/wiki/Chomsky_hierarchy">I have bad news...</a> a regular language has no context. ... Regexes will only solve a subproblem of your problem.
</blockquote></p>
<p>from [isbn://9780596004927]: Programming Perl (4th Ed), Pattern Matching - Chapter 5, p. 167
<blockquote>
If you're acquainted with regular expressions from some other venue, we should warn you that regular expressions are a bit different in Perl. First they aren't entirely "regular" in the theoretical sense of the word, which means they can do much more than the traditional regular expressions taught in Computer Science classes.
</blockquote>
Mentioned similarly in <a href="https://en.wikipedia.org/wiki/Regular_expression#Patterns_for_non-regular_languages">Wikipedia</a>
</p>
<p>Brackets with Perl regex is a FAQ, [doc://perlfaq6#Can-I-use-Perl-regular-expressions-to-match-balanced-text?], and is also covered in <a href="https://www.rosettacode.org/wiki/Balanced_brackets#Perl">Rosetta Code</a>. The regex techniques used are relatively new(er) and somewhat advanced but other answers have discussed modules that hide the technique behind a simple interface.</p>
<p>Correction based on feedback from [mr_mischief] below:</p>
<p>I also studied "regular languages"/"regular sets" in computer science and, <strike>understand the confusion</strike> while understanding the intention to avoid unneeded extensions, worry that ignoring all extensions to the more formal concept of a regular expression will cause more confusion. The Wikipedia article mentions backreferences as an example of a very commonly used extension. I don't really see the difference covered in [doc://perlre] , [doc://perlrequick] or [doc://perlretut] and would be interested in any suggestions on finding or adding the information for any of those documents.</p>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-1143060">
Ron
</div></div>
1218434
1218466