Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

News regexp search #414

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions news/fx-feature-399.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
`regex_search()`: Function Reworked

The `regex_search()` function has been updated to simplify behavior and enhance configurability:

- **Consistent Return Type**:
The legacy behavior of changing the return type (`dict` or `list`) based on the presence of named match groups has been removed. The function now always returns a `dict` by default.

- **Override with `list_mode`**: Use the `list_mode` optional named argument flag to explicitly return a `list` of match groups instead.

**Example**:
```python
result = regex_search("24-02-2024", /(?<date>(\d{2})-(\d{2})-(\d{4}))/)
result = regex_search("24-02-2024", /(?<date>(\d{2})-(\d{2})-(\d{4}))/, list_mode=True)
```

- **Result Type from Existing Objects**:
If `result` is an existing `filterx` object with a specific type (`dict` or `list`), the function respects the type of the object, independent of the `list_mode` flag.

- **Match Group 0 Handling**:
Match group `0` is now excluded from the result by default (since it is rarely used), unless it is the only match group. To include match group `0` in the result, use the `keep_zero` optional named argument flag.

**Example**:
```python
result = regex_search("24-02-2024", /(?<date>(\d{2})-(\d{2})-(\d{4}))/, keep_zero=True)
```
Loading