Skip to content

[Repo Assist] feat(stdlib): add re (regular expressions) module bindings#273

Draft
github-actions[bot] wants to merge 1 commit intomainfrom
repo-assist/bindings-re-regex-2026-04-23-e9ac9300e48a782a
Draft

[Repo Assist] feat(stdlib): add re (regular expressions) module bindings#273
github-actions[bot] wants to merge 1 commit intomainfrom
repo-assist/bindings-re-regex-2026-04-23-e9ac9300e48a782a

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated pull request from Repo Assist, an AI assistant for this repository.

Summary

Adds F# bindings for Python's [re]((docs.python.org/redacted) (regular expressions) module — one of the most widely used stdlib modules, and a gap identified in the repo's future work notes.

Component What's bound
Match group(), groups(), groupdict(), start(), end(), span(), expand(), string, pos, endpos, lastindex, lastgroup
Pattern match(), search(), fullmatch(), findall(), finditer(), sub(), subn(), split(), pattern, flags, groups, groupindex
Module functions compile, match, search, fullmatch, findall, finditer, sub, subn, split, escape, purge
Flags module IGNORECASE/I, MULTILINE/M, DOTALL/S, ASCII/A, LOCALE/L, UNICODE/U, VERBOSE/X, NOFLAG

Usage example

open Fable.Python.Regex

// Simple match
let m = re.``match`` ("([a-z]+) ([0-9]+)", "hello 42")
match m with
| None -> printfn "no match"
| Some m ->
    m.group ()        // "hello 42"
    m.group 1         // Some "hello"
    m.group 2         // Some "42"
    m.span ()         // (0, 8)

// Compiled pattern (efficient for repeated use)
let pat = re.compile ("[0-9]+", Flags.IGNORECASE)
let results = pat.findall "there are 3 cats and 42 dogs"
// ["3"; "42"]

// Substitution
re.sub ("[aeiou]", "*", "hello world")  // "h*ll* w*rld"

// Split
re.split (@"\s+", "a  b   c")  // [|"a"; "b"; "c"|]

Files changed

  • src/stdlib/Regex.fs — new bindings (module Fable.Python.Regex)
  • test/TestRegex.fs — 42 tests covering all major APIs
  • src/Fable.Python.fsproj — include new source file
  • test/Fable.Python.Test.fsproj — include new test file

Design notes

  • Module is named Fable.Python.Regex (not Re) to avoid collision with F#'s own Regex from System.Text.RegularExpressions, and the binding value is re to mirror Python's import re.
  • Match and Pattern are bound as [<Import(..., "re")>] classes with nativeOnly members — the same pattern as Queue, datetime, etc. Users never construct them directly.
  • end is a reserved word in F# so is escaped as end in both the binding and tests.
  • match is a reserved word in F# so is escaped as match where it appears as a method name on Pattern and as a module function. The IExports abstract match method uses backticks correctly.
  • The Flags sub-module uses [<Literal>] integer constants so they can be used in ||| combinations.
  • No existing signatures changed; this is a purely additive PR.
  • Note: CHANGELOG.md is intentionally not updated per repository policy.

CI will validate the build and Python tests.

Note

🔒 Integrity filter blocked 10 items

The following items were blocked because they don't meet the GitHub integrity level.

To allow these resources, lower min-integrity in your GitHub frontmatter:

tools:
  github:
    min-integrity: approved  # merged | approved | unapproved | none

Generated by Repo Assist · ● 3.3M ·

Adds F# bindings for Python's re module, covering:

- Match object: group(), groups(), groupdict(), start(), end(), span(),
  expand(), string, pos, endpos, lastindex, lastgroup
- Pattern object: match(), search(), fullmatch(), findall(), finditer(),
  sub(), subn(), split(), pattern, flags, groups, groupindex
- Module-level functions: compile, match, search, fullmatch, findall,
  finditer, sub, subn, split, escape, purge
- Flags module: IGNORECASE/I, MULTILINE/M, DOTALL/S, ASCII/A,
  LOCALE/L, UNICODE/U, VERBOSE/X, NOFLAG

Also adds 42 tests in test/TestRegex.fs covering all key APIs.

Note: CHANGELOG.md is intentionally not updated per repository policy.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants