Sorcerer's IsleDocs cfRegexOverviewCode

Metacharacters

A metacharacter is one or more characters that possess special meaning within a regex pattern, and can be used to build up the instructions which are used when applying a regex to a string.

Within a regex, everything is either a metacharacter or a literal character - the latter simply being a character that does not possess special meaning, but that matches the same character it represents.

The meaning of some metacharacters varies depending on if any regex modes are enabled - for example, the caret "^" metacharacter always matches the start of a string, but if Multiline mode is enabled, it also matches the start of a line.

In addition to different modes, it is important to be aware that there are two sets of metacharacters: those that only apply when in a normal expression, and a different (smaller) set which only apply when inside a character class. (For example, inside a character class the caret means "not", if it is the first character.)

Perhaps the most important metacharacter is the backslash "\" which has the ability to escape or create metacharacters by preceeding another character. That is, by using "\^", you are escaping the metacharacter and indicating the literal caret character should be matched at this point, whilst doing "\b" will instead create a metacharacter, which in this case tells the regex engine to match a word boundary at that point.

Different regex implementations can have different metacharacters - and some use the same metacharacters but may have subtly different meanings - so it is important to ensure you know what metacharacters to use for the particular regex engine which you are using.

The specific meanings of metacharacters is defined in the pages describing their features, or you can refer to the metacharacter reference chart for an overview.