BytePane

Lookbehind (Positive) Regex Pattern

Demonstrates positive lookbehind: matches numbers only when preceded by $. Extracts prices without the dollar sign.

Advanced Patterns
Advanced
Difficulty
JavaScript
Language
g
Flags
// Regular Expression
/(?<=\$)\d+(\.\d{2})?/g

Live Regex Tester

Pattern Breakdown

(?<=\$)\d+(\.\d{2})?
Character class [ ]
Group ( )
Quantifier { }
Anchor ^ $
Repetition * + ?
Escape \
Alternation |
Any char .

Code Examples

JavaScript

const regex = /(?<=\$)\d+(\.\d{2})?/g;
const test = "Price: $49.99";
console.log(regex.test(test)); // true

// Extract matches
const matches = test.match(regex);
console.log(matches);

Python

import re

pattern = r'(?<=\$)\d+(\.\d{2})?'
test = "Price: $49.99"
match = re.findall(pattern, test)
print(match)  # Found!

Go

package main

import (
    "fmt"
    "regexp"
)

func main() {
    re := regexp.MustCompile(`(?<=\$)\d+(\.\d{2})?`)
    fmt.Println(re.MatchString("Price: $49.99")) // true
}

Common Use Cases

Price extractionfinancial data parsingcurrency processing

Match Examples

InputResult
Price: $49.99Match
Price: 49.99No Match

About the Lookbehind (Positive) Regex

Demonstrates positive lookbehind: matches numbers only when preceded by $. Extracts prices without the dollar sign.

Regular expressions (regex) are powerful pattern matching tools used across virtually all programming languages. The lookbehind (positive) pattern is classified as advanced difficulty in the advanced patterns category. This pattern is specifically designed for JavaScript.

When using this regex, always consider edge cases and test thoroughly with real-world data. Use the interactive tester above to validate the pattern against your specific inputs before deploying to production.

Need More Regex Patterns?

Browse our complete library of 100+ regex patterns with interactive testers.

Frequently Asked Questions

What is the Lookbehind (Positive) regex pattern?

Demonstrates positive lookbehind: matches numbers only when preceded by $. Extracts prices without the dollar sign.

How do I use the Lookbehind (Positive) regex?

Use the pattern /(?<=\$)\d+(\.\d{2})?/g in your code. In JavaScript: new RegExp('(?<=\$)\d+(\.\d{2})?', 'g'). Test it above with your own input.

What does this Lookbehind (Positive) regex match?

This pattern matches: "Price: $49.99". It does NOT match: "Price: 49.99". Price extraction, financial data parsing, currency processing.

Is the Lookbehind (Positive) regex beginner-friendly?

This pattern is rated Advanced. It uses advanced features like lookaheads, backreferences, or complex alternation.

What languages support the Lookbehind (Positive) regex?

This pattern works in JavaScript. Syntax may vary slightly between regex engines.

Can I modify the Lookbehind (Positive) regex for my use case?

Yes! Use the interactive tester above to modify the pattern and test with your own data. Common modifications include making it case-insensitive (add 'i' flag), matching globally (add 'g' flag), or adjusting character classes.

Related Tools