“Number” is one of the patterns that you can select on the Match panel. Use this pattern to make a field match a decimal number that may or may not have decimals, thousand separators, currency symbols, signs, exponents, etc.
This example shows how you can use the “number” pattern to make your regular expression match a pH values. pH values range from 1.0 to 14.0. For this example, we’ll allow one optional decimal. You can find this example as “Pattern: number (basic)” in the RegexMagic library.
Valid pH values: 1 1.0 2.9 4 7.2 10.4 14 14.0 Invalid pH values: -7.2 -4 .8 0.9 14.1 15.1
button to add field
.

\A(?:1[0-4]|[1-9])(?:\.[0-9])?\z
Unused options: Case sensitive; Exact spacing; Dot doesn’t match line breaks; ^$ don’t match at line breaks; Numbered capture.
Valid pH values: 1 1.0 2.9 4 7.2 10.4 14 14.0 Invalid pH values: -7.2 -4 .8 0.9 14.1 15.1
The regular expression we just created isn’t perfect. 14.1 is not a valid pH value. The problem is that the “number” pattern in RegexMagic only has options to limit the range of the integer part, and to limit the number of decimal digits. It doesn’t have an option to limit the decimal part to specific values, so all we could do was to configure the pattern to match numbers between 1 and 14 with one decimal, resulting in a range from 1.0 to 14.9.
We can solve this problem by limiting the number pattern to a range from 1.0 to 13.9. We can then add alternatives to make our regular expression match the 14 and 14.0 values. The “Pattern: number (improved)” example in the RegexMagic library has the final result. These steps create the same if you continue from the above steps:
. When you do this, RegexMagic adds field
as the first alternative under field
, and sets the new field to use the “number” pattern that we configured previously.
to add field
as the last field under field
. The new field defaults to the same “number” pattern.
selected from the previous step. In the “pattern to match field” drop-down list, select “literal text”.
.
to add field
after field
. The new field defaults to the same “literal text” pattern.
.\A(?:(?:1[0-3]|[1-9])(?:\.[0-9])?|14|14\.0)\z
Unused options: Case sensitive; Exact spacing; Dot doesn’t match line breaks; ^$ don’t match at line breaks; Numbered capture.
Valid pH values: 1 1.0 2.9 4 7.2 10.4 14 14.0 Invalid pH values: -7.2 -4 .8 0.9 14.1 15.1
You’ll notice that three different colors now appear on the Samples panel. The yellow field
highlighting we had previously is gone. Field
is now an alternation field. Alternation fields don’t match any text directly, but simply alternate between several fields. In our formula, field
has three alternatives. Field
matches a number between 1.0 and 13.9. Field
matches “14”. Field
matches “14.0”. The highlighting on the Samples panel indicates which field matched which text.