forked from axoflow/axosyslog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: shifter <[email protected]>
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
``` |