Skip to content

Add REGEX function to formula#75

Open
ombr wants to merge 2 commits intomainfrom
cursor/add-regex-function-to-formula-090e
Open

Add REGEX function to formula#75
ombr wants to merge 2 commits intomainfrom
cursor/add-regex-function-to-formula-090e

Conversation

@ombr
Copy link
Owner

@ombr ombr commented Jun 24, 2025

The REGEX function was added to src/functions.ts to enable regular expression matching within formulas.

  • The function REGEX(text, regex_pattern) was implemented to return true if text matches regex_pattern, and false otherwise.
  • Argument validation was included to ensure both inputs are strings.
  • A key challenge was handling Salesforce-style double-escaped backslashes (e.g., \\d in formulas). The implementation now preprocesses the regex_pattern to convert \\\\ to \ before creating the JavaScript RegExp object, ensuring correct pattern interpretation.
  • Comprehensive tests were added to test/formula.test.ts.
    • 60 new test cases cover basic matching, character classes, quantifiers, anchors, and real-world Salesforce examples (email, phone, ZIP, SSN, credit card).
    • Tests also cover error handling for invalid arguments or malformed regex patterns.
  • All 374 tests, including the 60 new REGEX tests, are now passing, confirming the function's correct behavior and no regressions.

@ombr ombr self-assigned this Jun 24, 2025
…lementation

- implement REGEX(text, pattern) function following Salesforce specification
- handle Salesforce-style double-escaped backslashes (\\d becomes \d)
- add 60 comprehensive test cases covering:
  * basic pattern matching and character classes
  * quantifiers, anchors, and groups
  * real-world validation patterns (email, phone, ZIP, SSN, credit cards)
  * error handling and edge cases
- enhanced error messages with detailed JavaScript RegExp error information
- all tests pass with proper linting and formatting

resolves the requirement to add REGEX function to the formula engine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants