|
constexpr static const char * | getCaptureGroupName (int i) |
|
template<typename CharT > |
static bool | isCompleteMatch (const StringView< CharT > &str) |
| Returns true iff the regular expression matches the entire target string. More...
|
|
template<typename CharT > |
static Match | getCompleteMatch (const StringView< CharT > &str) |
| Returns a match iff the regular expression matches the entire target string. More...
|
|
template<typename CharT > |
static bool | hasPrefixMatch (StringView< CharT > str) |
| Returns true iff the regular expression matches the beginning of the string. More...
|
|
template<typename CharT > |
static Match | matchPrefix (StringView< CharT > str) |
| Returns the match starting at the beginning of the string. More...
|
|
template<typename CharT > |
static __host__ bool | hasMatch (StringView< CharT > str) |
| Returns true iff the regular expression matches a substring of the string. More...
|
|
template<typename CharT > |
static __host__ Match | findFirst (StringView< CharT > str) |
| Returns the first match of a substring in the string. More...
|
|
template<bool Noncapturing = false, typename CharT , typename MatchConsumer > |
static __host__ void | mapOverMatches (StringView< CharT > str, MatchConsumer mc) |
| Map a function over the matches in a string. More...
|
|
template<typename CharT > |
static __host__ std::vector< Match > | findAll (StringView< CharT > str) |
| Find all the matches of this regex in the string. More...
|
|
template<typename CharT > |
static __host__ int | findFirstN (StringView< CharT > str, Match *output, int n) |
| Find the first n matches of this regex in the string (or all of the matches if there are fewer than n). More...
|
|
template<typename CharT , typename MatchInterpolator > |
static __host__ int | inplaceNonincreasingReplaceAllWithLambda (StringView< CharT > &str, MatchInterpolator mi) |
|
template<ReplacementMode RM, typename CharT , typename MatchInterpolator > |
static __host__ int | replaceAllWithLambda (StringView< const CharT > str, StringView< CharT > &out, MatchInterpolator mi) |
|
template<typename ReplacementString , ReplacementMode RM = ReplacementMode::SAFE, typename CharT > |
static __host__ int | replaceAll (StringView< const CharT > str, StringView< CharT > &out) |
| Replace all matches of this regex in str with the pattern described by ReplacementString . More...
|
|
template<ReplacementMode RM = ReplacementMode::SAFE, typename CharT > |
static __host__ int | replaceAllWithLiteral (StringView< const CharT > str, StringView< const CharT > replacement, StringView< CharT > &out) |
| Replace all matches of this regex in str with the literal string replacement. More...
|
|
template<typename CharT , typename MatchInterpolator , typename Allocator = decltype(arrayAllocator<CharT>), typename Deallocator = decltype(arrayDeleter<CharT>)> |
static __host__ int | inplaceAllocatingReplaceAllWithLambda (StringView< CharT > &buffer, int inputLength, MatchInterpolator mi, Allocator alloc=arrayAllocator< CharT >, Deallocator dealloc=arrayDeleter< CharT >) |
| Perform an inplace replace-all which can allocate more memory if the output is too large, using a lambda to generate the replacements. More...
|
|
template<typename CharT , typename Allocator = decltype(arrayAllocator<CharT>), typename Deallocator = decltype(arrayDeleter<CharT>)> |
static __host__ int | inplaceAllocatingReplaceAllWithLiteral (StringView< CharT > &buffer, int inputLength, StringView< const CharT > replacement, Allocator alloc=arrayAllocator< CharT >, Deallocator dealloc=arrayDeleter< CharT >) |
| Perform an inplace replace-all with a string literal, which can allocate more memory if the output is too large. More...
|
|
template<typename CharT , typename MatchInterpolator > |
static __host__ int | inplaceExpandingReplaceAllWithLambda (StringView< CharT > &buffer, int inputLength, MatchInterpolator mi) |
| Perform an inplace replace-all which can use extra space in the buffer if the output needs to grow. More...
|
|
template<typename RegexStr, typename TuningParameters = RegexTuningParameters>
class sp::regex::Regex< RegexStr, TuningParameters >
A regex.
Use the REGEX_PATTERN
macro to initialise the template parameter with your regex:
A regex.
Definition: Regex.hpp:56
The regex is parsed in the C++ template system and specialised code generated for it.
Complicated regexes may have a detrimental effect on compile-time. You can mitigate this by spreading your regexes across more translation units.
Example
CPU-side string search, with extraction of submatches.
#include <spec/regex/Regex.hpp>
{
Trains are cool.
Potatoes are cool.
Beige is definitely not cool.
)";
using coolRegex =
sp::regex::Regex<REGEX_PATTERN(
"([a-zA-Z]+) (?:is|are) cool")>;
out << "The following things are cool:\n";
auto lambda = [&](const coolRegex::Match match) {
out << EXAMPLE_STRING.
substr(matchBounds) <<
'\n';
return false;
};
coolRegex::mapOverMatches(EXAMPLE_STRING, lambda);
}
constexpr ThisType substr(IntT pos=0, IntT count=npos)
- See also
- sp::regex::GPURegexMatcher For how to use GPU matching.
- Template Parameters
-
RegexStr | The regex to match. |
template<typename RegexStr , typename TuningParameters = RegexTuningParameters>
template<bool Noncapturing = false, typename CharT , typename MatchConsumer >
Map a function over the matches in a string.
The MatchConsumer function should return a boolean specifying whether to abort searching; this is useful if you only want to process the first n matches, for instance.
The MatchConsumer function will be evaluated sequentially on all matches in the string, terminating when it returns true or when all the matches in the string have been exhausted (whichever is first).
template<typename RegexStr , typename TuningParameters = RegexTuningParameters>
template<typename ReplacementString , ReplacementMode RM = ReplacementMode::SAFE, typename CharT >
Replace all matches of this regex in str
with the pattern described by ReplacementString
.
The input and output StringViews must be disjoint.
ReplacementString
can use most of the language features for regex replacement strings, documented here.
An overload for this API is provided to allow specification of ReplacementMode
or PrefixFilterDepth
or neither.
- Template Parameters
-
ReplacementString | A replacement pattern specification. |
ReplacementMode | SAFE , UNSAFE , or INPLACE . Only set to UNSAFE if the output buffer is known to be sufficient. Defaults to SAFE . |
- Parameters
-
str | String to search. |
out | Memory to overwrite with the output. This must be sufficiently large. This view will have its size reduced to represent the output string. |
- Returns
- the number of characters that would be in the output string if the buffer were large enough.