www.delorie.com/gnu/docs/gcc/gnat_ug_162.html   search  
 
Buy the book!


Untitled Document

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12.4 Regular Expressions in gnatfind and gnatxref

As specified in the section about gnatfind, the pattern can be a regular expression. Actually, there are to set of regular expressions which are recognized by the program :

globbing patterns
These are the most usual regular expression. They are the same that you generally used in a Unix shell command line, or in a DOS session.

Here is a more formal grammar :
 
regexp ::= term
term   ::= elmt            -- matches elmt
term   ::= elmt elmt       -- concatenation (elmt then elmt)
term   ::= *               -- any string of 0 or more characters
term   ::= ?               -- matches any character
term   ::= [char {char}] -- matches any character listed
term   ::= [char - char]   -- matches any character in range

full regular expression
The second set of regular expressions is much more powerful. This is the type of regular expressions recognized by utilities such a `grep'.

The following is the form of a regular expression, expressed in Ada reference manual style BNF is as follows

 
regexp ::= term {| term} -- alternation (term or term ...)

term ::= item {item}     -- concatenation (item then item)

item ::= elmt              -- match elmt
item ::= elmt *            -- zero or more elmt's
item ::= elmt +            -- one or more elmt's
item ::= elmt ?            -- matches elmt or nothing
elmt ::= nschar            -- matches given character
elmt ::= [nschar {nschar}]   -- matches any character listed
elmt ::= [^^^ nschar {nschar}] -- matches any character not listed
elmt ::= [char - char]     -- matches chars in given range
elmt ::= \ char            -- matches given character
elmt ::= .                 -- matches any single character
elmt ::= ( regexp )        -- parens used for grouping

char ::= any character, including special characters
nschar ::= any character except ()[].*+?^^^

Following are a few examples :

`abcde|fghi'
will match any of the two strings 'abcde' and 'fghi'.

`abc*d'
will match any string like 'abd', 'abcd', 'abccd', 'abcccd', and so on

`[a-z]+'
will match any string which has only lowercase characters in it (and at least one character


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003