# On the new \`regex\` module

**URL:** <https://forum.modular.com/t/on-the-new-regex-module/1413>\
**Category:** Mojo\
**Created:** [May 9, 2025, 11:07am UTC](https://forum.modular.com/t/on-the-new-regex-module/1413 "2025-05-09T11:07:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gryznar](https://avatars.discourse-cdn.com/v4/letter/g/e5b9ba/32.png) [@gryznar](https://forum.modular.com/u/gryznar)\
**Post date:** [May 9, 2025, 11:07am UTC](https://forum.modular.com/t/on-the-new-regex-module/1413/1 "2025-05-09T11:07:17Z")

</div>

Do we need to copy Python API here? This API is:

- inconsistent (flatcase `fullmatch`)
- unnecessary abbreviated (`sub` - substitute - this one is also inconsistent with `string.replace()` which purpose is the same)
- far away from SotA implementation.

I propose:

1. Dropping Python names and picking self-explanatory and consistent ones. Support for Python API could be added later via extensions and `re` module. This way we avoid same names with changes in behavior
2. Considering implementations in other system level langs like Rust / Zig to prioritize performance

@joe @adakkak

---

<div class="post-metadata">

**Author:** ![gryznar](https://avatars.discourse-cdn.com/v4/letter/g/e5b9ba/32.png) [@gryznar](https://forum.modular.com/u/gryznar)\
**Post date:** [May 9, 2025, 2:03pm UTC](https://forum.modular.com/t/on-the-new-regex-module/1413/2 "2025-05-09T14:03:55Z")

</div>

Another case to consider. Do free functions at module level work well? I am not sure with current implementation. Consider Python code:

```python
from re import sub

sub('foo+', 'foo', text)

```

At first glance it is not obvious for what `sub` is referring to. It only has sense with module name itself:

```python
import re

re.sub('foo+', 'foo', text)

```

---

<div class="post-metadata">

**Author:** ![gryznar](https://avatars.discourse-cdn.com/v4/letter/g/e5b9ba/32.png) [@gryznar](https://forum.modular.com/u/gryznar)\
**Post date:** [May 10, 2025, 10:37pm UTC](https://forum.modular.com/t/on-the-new-regex-module/1413/3 "2025-05-10T22:37:00Z")

</div>

This module has been removed. I am fine with it. It is better to provide regex handling in the future in a good state from the beginning rather than half baked Python-like API to just have something

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex001/uploads/modular/original/1X/2751e0fbdc595a99718b216730957e9db4448cfd.jpeg) [@system](https://forum.modular.com/u/system)\
**Post date:** [November 7, 2025, 8:45pm UTC](https://forum.modular.com/t/on-the-new-regex-module/1413/5 "2025-11-07T20:45:48Z")

</div>

Closed on November 7, 2025, 8:45pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
