Pattern matching, Simple regular expressions – HP Integrity NonStop J-Series User Manual
Page 53

Click on the banner to return to the user guide home page.
©Copyright 1996 Rogue Wave Software
Pattern Matching
Class
RWCString
supports a convenient interface for string searches. In the example below, the
code fragment:
RWCString s("curiouser and curiouser.");
size_t i = s.index("curious");
will find the start of the first occurrence of curious in s. The comparison will be case sensitive,
and the result will be that i is set to 0. To find the index of the next occurrence, you would use:
i = s.index("curious", ++i);
which will result in i set to 14. You can make a case-insensitive comparison with:
RWCString s("Curiouser and curiouser.");
size_t i = s.index("curious", 0, RWCString::ignoreCase);
which will also result in i set to 0.
If the pattern does not occur in the string, the index() will return the special value RW_NPOS.
Simple Regular Expressions
As part of its pattern matching capability, the Tools.h++ Class Library supports regular
expression searches. See the Class Reference, under
RWCRegexp
, for details of the regular
expression syntax. You can use a regular expression to return a substring; for example, here's
how you might match all Windows messages (prefix WM_):
#include
#include
#include
main(){
RWCString a("A message named WM_CREATE");
// Construct a Regular Expression to match Windows messages:
RWCRegexp re("WM_[A-Z]*");
cout << a(re) << endl;