Differences between RegExpr and Perl

RegExpr for VB & VBA was developed to mimic the behavior of regular expressions in the Perl programming language. Specifically, Perl 4.0.1.6 for MS-DOS, with a few differences, plus a few additional features introduced in Perl 5. Known differences are as follows.

Newline is two characters long

The default setting is that the newline character is a 2-character pair CR+LF (Const NewLine = vbCrLf). The pair CR+LF is treated as two characters otherwise but as one character in the following expressions:

\nThis matches pair CR+LF
\sThis matches pair CR+LF (two whitespace characters in one go)

Newline in range expressions [\n-..] and [..-\n] is invalid

You can't start or end a range with \n with the default setting Const NewLine = vbNewline since it's two characters, but a range must start and end with just one character. Use \r for CR or \cJ for LF.

Whitespace

The whitespace characters (\s) in RegExpr are: space, the newline sequence, tab (ASCII 9), return (ASCII 13) and line feed (ASCII 10). This doesn't include any other whitespace characters such as form feed as in Perl.

The same difference also applies to the non-whitespace characters (\S).

Word characters

The word characters (\w) and non-word characters (\W) have a different definition from that of Perl. This also affects word boundary \b and not word boundary \B.

Octal numbers

RegExpr requires octal numbers to start with a leading \0 followed by 1 to 3 digits in range \00..\0377. In addition, \0 is the NULL character.

Perl doesn't use the leading zero. It supports 2 to 3 digit octal numbers in range \00..\377. Perl doesn't accept 4-digit sequences such as \0100..\0377. So, while \0377 is octal 377 in RegExpr, it is \037 followed by 7 in Perl. And while \37 is octal 37 in Perl, it is \3 followed by 7 in RegExpr.

(?imsx) not supported

The (?imsx) syntax for setting flags, a feature introduced in Perl 5, is not supported. Flags are set in the function call to RegExpr.

Newer syntax unsupported

Perl also supports numerous newer regex features not mentioned in this help. RegExpr doesn't support them.

©Aivosto Oy · RegExpr Help