Parasol Framework
  • Gallery
  • API
  • Wiki
  • GitHub
    •  Overview
    • Compile()
    • GetCaptureIndex()
    • Replace()
    • Search()
    • Split()
    • Audio
    • Core
    • Display
    • Fluid
    • Font
    • Network
    • Regex
    • Vector
    • XML
    • XPath
      • Audio
      • Sound
      • File
      • MetaClass
      • Module
      • StorageDevice
      • Task
      • Thread
      • Time
      • Compression
      • CompressedStream
      • Config
      • Script
      • XML
      • Controller
      • BlurFX
      • ColourFX
      • CompositeFX
      • ConvolveFX
      • DisplacementFX
      • FilterEffect
      • FloodFX
      • ImageFX
      • LightingFX
      • MergeFX
      • MorphologyFX
      • OffsetFX
      • RemapFX
      • SourceFX
      • TurbulenceFX
      • WaveFunctionFX
      • Scintilla
      • ScintillaSearch
      • Bitmap
      • Clipboard
      • Display
      • Document
      • Font
      • Picture
      • Pointer
      • Surface
      • SVG
      • ClientSocket
      • HTTP
      • NetClient
      • NetLookup
      • NetSocket
      • Proxy
      • Vector
      • VectorClip
      • VectorColour
      • VectorEllipse
      • VectorFilter
      • VectorGradient
      • VectorGroup
      • VectorImage
      • VectorPath
      • VectorPattern
      • VectorPolygon
      • VectorRectangle
      • VectorScene
      • VectorShape
      • VectorSpiral
      • VectorText
      • VectorTransition
      • VectorViewport
      • VectorWave
      • Linux Builds
      • Windows Builds
      • Customising Your Build
      • Parasol Objects
      • Parasol In Depth
      • Fluid Reference Manual
      • Common API
      • FileSearch API
      • GUI API
      • JSON API
      • VFX API
      • Widgets
      • RIPL Reference Manual
      • Parasol Cmd Tool
      • Flute / Unit Testing
      • Embedded Document Format
      • FDL Reference Manual
      • FDL Tools
      • Action Reference Manual
      • System Error Codes

Regex Module

Provides support for regular expression pattern matching and text processing.

The Regex module provides ECMAScript-compatible regex functionality with Unicode support. It offers efficient pattern compilation, flexible matching modes, and text manipulation capabilities including search, replace, and split operations.

Key features include:

  • ECMAScript (JavaScript) regex syntax.
  • Full Unicode support including character classes and properties.
  • Case-insensitive and multiline matching options.
  • Reusable compiled patterns for optimal performance.
  • Callback-based result processing for custom handling.

Note: Fluid scripts are expected to use the built-in regex functions for better integration as opposed to this module.

Functions

Compile | GetCaptureIndex | Replace | Search | Split

Structures

Regex

Constants

REGEX | RMATCH

Compile()

Compiles a regex pattern and returns a regex object.

ERR rx::Compile(const std::string_view & Pattern, REGEX Flags, std::string * ErrorMsg, struct Regex ** Result)
ParameterDescription
PatternA regex pattern string.
FlagsOptional flags.
ErrorMsgOptional reference for storing custom error messages.
ResultPointer to store the created regex object.

Use Compile() to compile a regex pattern into a regex object that can be used for matching and searching. The compiled regex object can be reused for multiple match or search operations, improving performance. It must be removed with ~Core:FreeResource() when no longer needed to avoid memory leaks.

Error Codes

OkayOperation successful.
AllocMemoryAllocMemory() failed to create a new memory block.
SyntaxInvalid syntax detected.
NullArgsFunction call missing argument value(s)
Regex module documentation © Paul Manias © 2025

GetCaptureIndex()

Retrieves capture indices for a named group.

ERR rx::GetCaptureIndex(struct Regex * Regex, const std::string_view & Name, pf::vector<int> * Indices)
ParameterDescription
RegexThe compiled regex object.
NameThe capture group name to resolve.
IndicesReceives the resulting capture indices.

Use GetCaptureIndex() to resolve the numeric capture indices associated with a named capture group. ECMAScript allows multiple groups to share the same name; this function therefore returns every index that matches the provided name. If no capture groups match the provided name, ERR::Search is returned.

Error Codes

OkayThe name was resolved and Indices populated.
SearchThe provided name does not exist within the regex.
NullArgsOne or more required arguments were null.
Regex module documentation © Paul Manias © 2025

Replace()

Replaces occurrences of the regex pattern in the input text with a specified replacement string.

ERR rx::Replace(struct Regex * Regex, const std::string_view & Text, const std::string_view & Replacement, std::string * Output, RMATCH Flags)
ParameterDescription
RegexThe compiled regex object.
TextThe input text to perform replacements on.
ReplacementThe replacement string, which can include back-references like \1, \2, etc.
OutputReceives the resulting string after replacements.
FlagsOptional flags to modify the replacement behavior.

Call Replace() to perform regex-based replacements in a given text. The function takes a compiled regex object, the input text, a replacement string, and optional flags to modify the replacement behavior. The replacement string can include back-references like \1, \2, etc., to refer to captured groups from the regex match.

Error Codes

OkaySuccessful execution, does not necessarily mean replacements were made.
NullArgsOne or more required input arguments were null.
Regex module documentation © Paul Manias © 2025

Search()

Performs regex matching.

ERR rx::Search(struct Regex * Regex, const std::string_view & Text, RMATCH Flags, FUNCTION * Callback)
ParameterDescription
RegexThe compiled regex object.
TextThe input text to perform matching on.
FlagsOptional flags to modify the matching behavior.
CallbackReceives the match results.

Call Search() to search for a regex pattern in a given text. The function takes a compiled regex object, the input text, optional flags to modify the matching behavior, and a callback function to process the match results. For each match that is found, the callback function is invoked with details about the match.

The C++ prototype for the Callback function is:

ERR callback(int Index, std::vector<std::string_view> &Capture, size_t MatchStart, size_t MatchEnd, APTR Meta);

Note the inclusion of the Index parameter, which indicates the match number (starting from 0). The MatchStart and MatchEnd parameters provide explicit byte offsets into the input text for the matched region.

The Capture vector is always normalised so that its size matches the total number of capturing groups defined by the pattern (including the full match at index 0). Optional groups that did not match are provided as empty std::string_view instances, ensuring consistent indexing across matches.

Error Codes

OkayAt least one match was found and processed.
SearchNo matches were found.
NullArgsOne or more required input arguments were null.
Regex module documentation © Paul Manias © 2025

Split()

Split a string into tokens, using a regex pattern to denote the delimiter.

ERR rx::Split(struct Regex * Regex, const std::string_view & Text, pf::vector<std::string> * Output, RMATCH Flags)
ParameterDescription
RegexThe compiled regex object.
TextThe input text to split.
OutputReceives the resulting string tokens.
FlagsOptional flags to modify the splitting behavior.

Call Split() to divide a string into multiple tokens based on a regex pattern that defines the delimiters. The function takes a compiled regex object, the input text, and optional flags to modify the splitting behavior.

The resulting tokens are stored in the provided output array.

If no matches are found, the entire input text is returned as a single token.

Error Codes

OkayThe string was successfully split into tokens. If no matches are found, the entire input text is returned as a single token.
NullArgsOne or more required input arguments were null.
Regex module documentation © Paul Manias © 2025

REGEX Type

Optional flags for the Regex functions.

NameDescription
REGEX::DOT_ALL. matches newlines.
REGEX::ICASEIgnore case.
REGEX::MULTILINE^ and $ match line boundaries.
Regex module documentation © Paul Manias © 2025

RMATCH Type

NameDescription
RMATCH::CONTINUOUSRequires the match to start at the beginning of the sequence (anchored matching).
RMATCH::NOT_BEGIN_OF_LINETreats the first character in the sequence as NOT being at the beginning of a line, preventing ^ from matching at that position.
RMATCH::NOT_BEGIN_OF_WORDTreats the first character in the sequence as NOT being at the beginning of a word, affecting \b word boundary matching.
RMATCH::NOT_END_OF_LINETreats the last character in the sequence as NOT being at the end of a line, preventing $ from matching at that position.
RMATCH::NOT_END_OF_WORDTreats the last character in the sequence as NOT being at the end of a word, affecting \b word boundary matching.
RMATCH::NOT_NULLPrevents the regex engine from matching zero-length (empty) sequences.
RMATCH::PREV_AVAILABLEIndicates that a valid character exists before the first position in the sequence, enabling proper look-behind and boundary assertions.
RMATCH::REPLACE_FIRST_ONLYIn Replace(), replaces only the first match and leaves subsequent matches unchanged.
RMATCH::REPLACE_NO_COPYIn Replace(), prevents copying non-matched portions of the input to the output.
RMATCH::WHOLEImplicit ^...$ around the pattern.
Regex module documentation © Paul Manias © 2025

Regex Structure

Compiled regex structure.

FieldTypeDescription
Patternstd::stringOriginal pattern string
FlagsREGEXCompilation flags
Regex module documentation © Paul Manias © 2025