Description of a Regular Expression

The regular expression described here is used in Substituting a Regular Expression for a Recordset Field.

Regular expressions are complex. There are many references available, on the Internet, and elsewhere, to help you understand them more fully.

Expression: (^|[^-.\d])(\d+(?:\.\d+)?)-(?=[^-.\d]|$)

Replace with : $1-$2

A "capture group" is a regular expression surrounded by parentheses that is remembered as a numbered variable for use in the replacement.

Detail of Expression Description
(^|[^-.\d])
A numbered capture group
(Becomes $1 in the replacement)
Select from 2 alternatives:
Beginning of line or string
Any character that is not in this class: [-.\d] (minus, decimal, or digit)
(\d+(?:\.\d+)?)
A numbered capture group
(Becomes $2 in the replacement)
\d+(?:\.\d+)?
Any digit, one or more repetitions
Match expression but don't capture it. [\.\d+], zero or one repetitions \.\d+
Any digit, one or more repetitions
- (Match on trailing minus)
([^-.\d]|$)
Match a suffix but exclude it from the capture.
Select from 2 alternatives:
Any character that is not in this class: [-.\d] (minus, decimal, or digit)
End of line or string

This translates a string like "123.45-" to "-123.45".