Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Regex for outside of brackets

by mr_ron (Chaplain)
on Jul 16, 2018 at 00:31 UTC ( [id://1218526]=note: print w/replies, xml ) Need Help??


in reply to Re: Regex for outside of brackets
in thread Regex for outside of brackets

Are you sure you want a match, and that you can only use a single regex? I have bad news... a regular language has no context. ... Regexes will only solve a subproblem of your problem.

from ISBN 9780596004927: Programming Perl (4th Ed), Pattern Matching - Chapter 5, p. 167

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.
Mentioned similarly in Wikipedia

Brackets with Perl regex is a FAQ, Can I use Perl regular expressions to match balanced text?, and is also covered in Rosetta Code. 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.

Correction based on feedback from mr_mischief below:

I also studied "regular languages"/"regular sets" in computer science and, understand the confusion 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 perlre , perlrequick or perlretut and would be interested in any suggestions on finding or adding the information for any of those documents.

Ron

Replies are listed 'Best First'.
Re^3: Regex for outside of brackets
by mr_mischief (Monsignor) on Jul 16, 2018 at 17:48 UTC

    I hand-waived over Perl regexes not being entirely regular. They are still not (without doing really convoluted things) a Turing complete language. Matching the complement of the text that's bracketed is still a step beyond matching bracketed text. Just because one can hammer a screw does not make a hammer a screwdriver nor a screw a nail.

    I remember a time when helping people with questions that this community would actually try to offer advice on good, clean ways to do things. I'm unsure of the value of arguing that because something is strictly possible that we should help do things the wrong way.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1218526]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-03-28 20:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found