icon Top 9 categories map      RocketAware > Perl >

Can I use Perl regular expressions to match balanced text?

Tips: Browse or Search all pages for efficient awareness of Perl functions, operators, and FAQs.



Home

Search Perl pages


Subjects

By activity
Professions, Sciences, Humanities, Business, ...

User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...

Text Strings
Conversions, tests, processing, manipulation,...

Math
Integer, Floating point, Matrix, Statistics, Boolean, ...

Processing
Algorithms, Memory, Process control, Debugging, ...

Stored Data
Data storage, Integrity, Encryption, Compression, ...

Communications
Networks, protocols, Interprocess, Remote, Client Server, ...

Hard World
Timing, Calendar and Clock, Audio, Video, Printer, Controls...

File System
Management, Filtering, File & Directory access, Viewers, ...

    

Can I use Perl regular expressions to match balanced text?

Although Perl regular expressions are more powerful than ``mathematical'' regular expressions, because they feature conveniences like backreferences (\1 and its ilk), they still aren't powerful enough. You still need to use non-regexp techniques to parse balanced text, such as the text enclosed between matching parentheses or braces, for example.

An elaborate subroutine (for 7-bit ASCII only) to pull out balanced and possibly nested single chars, like ` and ', { and }, or ( and ) can be found in http://www.perl.com/CPAN/authors/id/TOMC/scripts/pull_quotes.gz .

The C::Scan module from CPAN contains such subs for internal usage, but they are undocumented.


Source: Perl FAQ: Regexps
Copyright: Copyright (c) 1997 Tom Christiansen and Nathan Torkington.
Next: What does it mean that regexps are greedy? How can I get around it?

Previous: How do I use a regular expression to strip C style comments from a file?



(Corrections, notes, and links courtesy of RocketAware.com)


[Overview Topics]

Up to: NUL terminated String Comparison and Search




Rapid-Links: Search | About | Comments | Submit Path: RocketAware > Perl > perlfaq6/Can_I_use_Perl_regular_expressio.htm
RocketAware.com is a service of Mib Software
Copyright 2000, Forrest J. Cavalier III. All Rights Reserved.
We welcome submissions and comments