Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TRegexp Class Reference

Regular expression class.

'^' // start-of-line anchor
'$' // end-of-line anchor
'.' // matches any character
'[' // start a character class
']' // end a character class
'^' // negates character class if 1st character
'*' // Kleene closure (matches 0 or more)
'+' // Positive closure (1 or more)
'?' // Optional closure (0 or 1)

Note that the '|' operator (union) is not supported, nor are parentheses (grouping). Therefore "a|b" does not match "a".

Standard classes like [:alnum:], [:alpha:], etc. are not supported, only [a-zA-Z], [^ntf] and so on.

Warning: The preferred way to use regular expressions is via std::regex. E.g., Index() functions may return incorrect result.

Definition at line 31 of file TRegexp.h.

Public Types

enum  EStatVal { kOK = 0 , kIllegal , kNomem , kToolong }
 

Public Member Functions

 TRegexp (const char *re, Bool_t wildcard=kFALSE)
 Create a regular expression from the input string.
 
 TRegexp (const TRegexp &re)
 Copy ctor.
 
 TRegexp (const TString &re)
 Create a regular expression from a TString.
 
virtual ~TRegexp ()
 Destructor.
 
Ssiz_t Index (const TString &str, Ssiz_t *len, Ssiz_t start=0) const
 Find the first occurrence of the regexp in string and return the position, or -1 if there is no match.
 
virtual TClassIsA () const
 
TRegexpoperator= (const char *re)
 Assignment operator taking a char* and assigning it to a regexp.
 
TRegexpoperator= (const TRegexp &re)
 Assignment operator.
 
TRegexpoperator= (const TString &re)
 Assignment operator taking a TString.
 
EStatVal Status ()
 Check status of regexp.
 
virtual void Streamer (TBuffer &)
 
void StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b)
 

Static Public Member Functions

static TClassClass ()
 
static const char * Class_Name ()
 
static constexpr Version_t Class_Version ()
 
static const char * DeclFileName ()
 

Private Member Functions

void CopyPattern (const TRegexp &re)
 Copy the regular expression pattern.
 
void GenPattern (const char *re)
 Generate the regular expression pattern.
 
const char * MakeWildcard (const char *re)
 This routine transforms a wildcarding regular expression into a general regular expression used for pattern matching.
 

Private Attributes

Pattern_tfPattern
 
EStatVal fStat
 

Static Private Attributes

static const unsigned fgMaxpat = 2048
 

#include <TRegexp.h>

Member Enumeration Documentation

◆ EStatVal

Enumerator
kOK 
kIllegal 
kNomem 
kToolong 

Definition at line 34 of file TRegexp.h.

Constructor & Destructor Documentation

◆ TRegexp() [1/3]

TRegexp::TRegexp ( const char *  re,
Bool_t  wildcard = kFALSE 
)

Create a regular expression from the input string.

If wildcard is true then the input string will first be interpreted as a wildcard expression by MakeWildcard(), and the result then interpreted as a regular expression.

Definition at line 54 of file TRegexp.cxx.

◆ TRegexp() [2/3]

TRegexp::TRegexp ( const TString re)

Create a regular expression from a TString.

Definition at line 65 of file TRegexp.cxx.

◆ TRegexp() [3/3]

TRegexp::TRegexp ( const TRegexp re)

Copy ctor.

Definition at line 73 of file TRegexp.cxx.

◆ ~TRegexp()

TRegexp::~TRegexp ( )
virtual

Destructor.

Definition at line 81 of file TRegexp.cxx.

Member Function Documentation

◆ Class()

static TClass * TRegexp::Class ( )
static
Returns
TClass describing this class

◆ Class_Name()

static const char * TRegexp::Class_Name ( )
static
Returns
Name of this class

◆ Class_Version()

static constexpr Version_t TRegexp::Class_Version ( )
inlinestaticconstexpr
Returns
Version of this class

Definition at line 57 of file TRegexp.h.

◆ CopyPattern()

void TRegexp::CopyPattern ( const TRegexp re)
private

Copy the regular expression pattern.

Definition at line 131 of file TRegexp.cxx.

◆ DeclFileName()

static const char * TRegexp::DeclFileName ( )
inlinestatic
Returns
Name of the file containing the class declaration

Definition at line 57 of file TRegexp.h.

◆ GenPattern()

void TRegexp::GenPattern ( const char *  re)
private

Generate the regular expression pattern.

Definition at line 121 of file TRegexp.cxx.

◆ Index()

Ssiz_t TRegexp::Index ( const TString string,
Ssiz_t len,
Ssiz_t  i = 0 
) const

Find the first occurrence of the regexp in string and return the position, or -1 if there is no match.

Len is length of the matched string and i is the offset at which the matching should start. Please, see the Warning in the class documentation above.

Definition at line 213 of file TRegexp.cxx.

◆ IsA()

virtual TClass * TRegexp::IsA ( ) const
inlinevirtual
Returns
TClass describing current object

Definition at line 57 of file TRegexp.h.

◆ MakeWildcard()

const char * TRegexp::MakeWildcard ( const char *  re)
private

This routine transforms a wildcarding regular expression into a general regular expression used for pattern matching.

When using wildcards the regular expression is assumed to be preceded by a "^" (BOL) and terminated by a "$" (EOL). Also, all "*"'s and "?"'s (closures) are assumed to be preceded by a "." (i.e. any character, except "/"'s) and all .'s are escaped (so *.ps is different from *.eps). The special treatment of "/" allows the easy matching of pathnames, e.g. "*.root" will match "aap.root", but not "pipo/aap.root".

Definition at line 148 of file TRegexp.cxx.

◆ operator=() [1/3]

TRegexp & TRegexp::operator= ( const char *  re)

Assignment operator taking a char* and assigning it to a regexp.

Definition at line 101 of file TRegexp.cxx.

◆ operator=() [2/3]

TRegexp & TRegexp::operator= ( const TRegexp re)

Assignment operator.

Definition at line 89 of file TRegexp.cxx.

◆ operator=() [3/3]

TRegexp & TRegexp::operator= ( const TString re)

Assignment operator taking a TString.

Definition at line 111 of file TRegexp.cxx.

◆ Status()

TRegexp::EStatVal TRegexp::Status ( )

Check status of regexp.

Definition at line 235 of file TRegexp.cxx.

◆ Streamer()

virtual void TRegexp::Streamer ( TBuffer )
virtual

◆ StreamerNVirtual()

void TRegexp::StreamerNVirtual ( TBuffer ClassDef_StreamerNVirtual_b)
inline

Definition at line 57 of file TRegexp.h.

Member Data Documentation

◆ fgMaxpat

const unsigned TRegexp::fgMaxpat = 2048
staticprivate

Definition at line 39 of file TRegexp.h.

◆ fPattern

Pattern_t* TRegexp::fPattern
private

Definition at line 37 of file TRegexp.h.

◆ fStat

EStatVal TRegexp::fStat
private

Definition at line 38 of file TRegexp.h.

  • core/base/inc/TRegexp.h
  • core/base/src/TRegexp.cxx