Repository: pydantic/pydantic

Issue:
Expose regex_engine flag
### Initial Checks

- [X] I have searched Google & GitHub for similar requests and couldn't find anything
- [X] I have read and followed [the docs](https://docs.pydantic.dev) and still think this feature is missing

### Description

pydantic-core 2.10.0 added a new flag `regex_engine` (https://github.com/pydantic/pydantic-core/pull/983).

Can you please also expose it in pydantic?



### Affected Components

- [ ] [Compatibility between releases](https://docs.pydantic.dev/changelog/)
- [ ] [Data validation/parsing](https://docs.pydantic.dev/concepts/models/#basic-model-usage)
- [ ] [Data serialization](https://docs.pydantic.dev/concepts/serialization/) - `.model_dump()` and `.model_dump_json()`
- [ ] [JSON Schema](https://docs.pydantic.dev/concepts/json_schema/)
- [ ] [Dataclasses](https://docs.pydantic.dev/concepts/dataclasses/)
- [X] [Model Config](https://docs.pydantic.dev/concepts/config/)
- [ ] [Field Types](https://docs.pydantic.dev/api/types/) - adding or changing a particular data type
- [ ] [Function validation decorator](https://docs.pydantic.dev/concepts/validation_decorator/)
- [ ] [Generic Models](https://docs.pydantic.dev/concepts/models/#generic-models)
- [ ] [Other Model behaviour](https://docs.pydantic.dev/concepts/models/) - `model_construct()`, pickling, private attributes, ORM mode
- [ ] [Plugins](https://docs.pydantic.dev/) and integration with other tools - mypy, FastAPI, python-devtools, Hypothesis, VS Code, PyCharm, etc.


Discussion:
I will aim to eventually get around to this, if anyone wants to pick this up in the interim and submit a PR please just ping to say you're claiming it!
Possibly only question is what exactly the API in `pydantic` looks like. I don't think that should be too hard to figure out.
Hey, I would like to try to solve this problem
@utkini please go ahead. I think the plumbing might already be in place such that if you just add `regex_engine: Literal['rust-regex', 'python-re']` to the `ConfigDict` type then the whole feature just works. If that's the case, then the rest of the task is about adding some documentation to explain how to use this and why.
Feel free to ping me if you need more details, or push a draft PR and we can collaborate.

Resolving patch:
diff --git a/pydantic/_internal/_config.py b/pydantic/_internal/_config.py
--- a/pydantic/_internal/_config.py
+++ b/pydantic/_internal/_config.py
@@ -80,6 +80,7 @@ class ConfigWrapper:
     json_schema_serialization_defaults_required: bool
     json_schema_mode_override: Literal['validation', 'serialization', None]
     coerce_numbers_to_str: bool
+    regex_engine: Literal['rust-regex', 'python-re']
 
     def __init__(self, config: ConfigDict | dict[str, Any] | type[Any] | None, *, check: bool = True):
         if check:
@@ -176,6 +177,7 @@ def dict_not_none(**kwargs: Any) -> Any:
                 str_min_length=self.config_dict.get('str_min_length'),
                 hide_input_in_errors=self.config_dict.get('hide_input_in_errors'),
                 coerce_numbers_to_str=self.config_dict.get('coerce_numbers_to_str'),
+                regex_engine=self.config_dict.get('regex_engine'),
             )
         )
         return core_config
@@ -248,6 +250,7 @@ def _context_manager() -> Iterator[None]:
     json_schema_serialization_defaults_required=False,
     json_schema_mode_override=None,
     coerce_numbers_to_str=False,
+    regex_engine='rust-regex',
 )
 
 
diff --git a/pydantic/config.py b/pydantic/config.py
--- a/pydantic/config.py
+++ b/pydantic/config.py
@@ -787,5 +787,38 @@ class Model(BaseModel):
     ```
     """
 
+    regex_engine: Literal['rust-regex', 'python-re']
+    """
+    The regex engine to used for pattern validation
+    Defaults to `'rust-regex'`.
+
+    - `rust-regex` uses the [`regex`](https://docs.rs/regex) Rust crate,
+      which is non-backtracking and therefore more DDoS resistant, but does not support all regex features.
+    - `python-re` use the [`re`](https://docs.python.org/3/library/re.html) module,
+      which supports all regex features, but may be slower.
+
+    ```py
+    from pydantic import BaseModel, ConfigDict, Field, ValidationError
+
+    class Model(BaseModel):
+        model_config = ConfigDict(regex_engine='python-re')
+
+        value: str = Field(pattern=r'^abc(?=def)')
+
+    print(Model(value='abcdef').value)
+    #> abcdef
+
+    try:
+        print(Model(value='abxyzcdef'))
+    except ValidationError as e:
+        print(e)
+        '''
+        1 validation error for Model
+        value
+          String should match pattern '^abc(?=def)' [type=string_pattern_mismatch, input_value='abxyzcdef', input_type=str]
+        '''
+    ```
+    """
+
 
 __getattr__ = getattr_migration(__name__)


Test patch: