Negative Lookbehind (Decimals Without $)
Use negative lookbehind `(?<!...)` to match decimal numbers NOT preceded by a dollar sign.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("(?<!\\$)\\b\\d+\\.\\d{2}\\b", "g");
const input = "Price $19.99 vs ratio 1.50";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
import re
pattern = re.compile(r"(?<!\$)\b\d+\.\d{2}\b")
input_text = "Price $19.99 vs ratio 1.50"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Why it doesn't work in GO
Go's RE2 engine doesn't support lookarounds (`(?=...)`, `(?<=...)`, etc.) — they break the linear-time matching guarantee.
Approach
Restructure to capture the surrounding context as a group instead, or use JS / Python where lookarounds are available.
Read the full guide →Workaround code in Go (RE2)
package main
import (
"fmt"
"regexp"
"unicode"
)
// RE2 doesn't support lookarounds. The fix: match a BROADER candidate
// without the lookaround, then verify the condition in Go code.
//
// Example: instead of `(?=.*\d)[A-Za-z\d]{8,}` (require a digit),
// match the candidate then check `HasDigit(s)` separately.
func HasDigit(s string) bool {
for _, r := range s {
if unicode.IsDigit(r) {
return true
}
}
return false
}
func main() {
re := regexp.MustCompile(`[A-Za-z\d]{8,}`) // simplified, no lookaround
input := "Password1 weakpass StrongerOne9"
for _, candidate := range re.FindAllString(input, -1) {
if HasDigit(candidate) { // the lookaround condition, in code
fmt.Println(candidate)
}
}
}Match a broader candidate without the lookaround, then verify the constraint in Go. Keeps the linear-time guarantee.
Pattern
(?<!\$)\b\d+\.\d{2}\b (flags: g)Raw source: (?<!\$)\b\d+\.\d{2}\b
How it works
Examples
Input
Price $19.99 vs ratio 1.50Matches
1.50
Input
Discount 10.00 off $99.99Matches
10.00
Input
$5.00 onlyNo match
—Common use cases
- •Extracting non-currency decimals from financial text
- •Linting rules that ignore certain prefixes
- •Filtering URL paths that don't begin with a marker
- •Selective text replacement avoiding marked tokens
Related patterns
Negative Lookahead
Text ProcessingUse negative lookahead `(?!...)` to match words that are NOT in a blocklist (here: log-level keywords).
JSON Key-Value Pair (Simple)
Text ProcessingExtract simple `"key": value` pairs from JSON-ish text (strings, numbers, booleans, null).
JSON Number (Strict)
Text ProcessingMatch JSON-spec numbers — disallows leading zeros (no `01`), allows decimals and exponents.
Non-Capturing Group (Image URL)
Text ProcessingUse non-capturing groups `(?:...)` to alternate without polluting the captured-groups list.