Skip to content

Commit

Permalink
news: add entry for regexp_search
Browse files Browse the repository at this point in the history
Signed-off-by: shifter <shifter@axoflow.com>
  • Loading branch information
bshifter committed Dec 9, 2024
1 parent 62228cd commit 48d480f
Showing 1 changed file with 25 additions and 0 deletions.
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)
```

0 comments on commit 48d480f

Please sign in to comment.