Regular Expression | re - Support String List Input Type List[str]

Hi Everyone, I would like to propose an idea for the regular expression module re.search(Pattern, Input) to support List[str] input type. So it will return a matched object list if the input is a string list. Otherwise, it will return a normal matched object, if the input is a normal string Best Regards Giang

On 2020-09-28 at 23:10:24 -0000, Giang Le <giang.lh0469@gmail.com> wrote:
I would like to propose an idea for the regular expression module re.search(Pattern, Input) to support List[str] input type.
How would that change be better than a new function: def regex_search_list(regex, pattern, list_of_inputs): [regex.search(pattern, input) for input in list_of_inputs] (or possibly an equivalent method of regexen)?

Hi, I would like to have the same function re.search(pattern, input) to keep main code structure to be the same. The input into the re.search function will be depended on other previous functions. It is also more dynamic for users. Thank you.

import re re_search = re.search def re_search_list(pattern, list_or_text): if isinstance(list_or_text, str): return re_search(pattern, list_or_text) return [re_search_list(pattern, i) for i in list_or_text] re.search = re_search_list Bottom line: no need to change the function, you can do it yourself. On Tue, Sep 29, 2020 at 06:19:29AM -0000, Giang Le <giang.lh0469@gmail.com> wrote:
Hi, I would like to have the same function re.search(pattern, input) to keep main code structure to be the same. The input into the re.search function will be depended on other previous functions. It is also more dynamic for users. Thank you.
Oleg. -- Oleg Broytman https://phdru.name/ phd@phdru.name Programmers don't die, they just GOSUB without RETURN.

would rather it took List[str] patterns instead, for matching against List[str] input. so you could do things like: pattern = ["foo", "?", "\", "?", "bar", "baz"] input = ["foo", "?", "bar", "baz"] # matches input = ["?", "bar", "baz"] # matches input = ["foo?barbaz"] # doesn't match bonus points if it also takes arbitrary objects: pattern = [None, True, False, "?"] input = [None, True] # matches input = [None, False] # doesn't match input = [None, True, False] #matches On 2020-09-28 8:10 p.m., Giang Le wrote:

On 2020-09-28 at 23:10:24 -0000, Giang Le <giang.lh0469@gmail.com> wrote:
I would like to propose an idea for the regular expression module re.search(Pattern, Input) to support List[str] input type.
How would that change be better than a new function: def regex_search_list(regex, pattern, list_of_inputs): [regex.search(pattern, input) for input in list_of_inputs] (or possibly an equivalent method of regexen)?

Hi, I would like to have the same function re.search(pattern, input) to keep main code structure to be the same. The input into the re.search function will be depended on other previous functions. It is also more dynamic for users. Thank you.

import re re_search = re.search def re_search_list(pattern, list_or_text): if isinstance(list_or_text, str): return re_search(pattern, list_or_text) return [re_search_list(pattern, i) for i in list_or_text] re.search = re_search_list Bottom line: no need to change the function, you can do it yourself. On Tue, Sep 29, 2020 at 06:19:29AM -0000, Giang Le <giang.lh0469@gmail.com> wrote:
Hi, I would like to have the same function re.search(pattern, input) to keep main code structure to be the same. The input into the re.search function will be depended on other previous functions. It is also more dynamic for users. Thank you.
Oleg. -- Oleg Broytman https://phdru.name/ phd@phdru.name Programmers don't die, they just GOSUB without RETURN.

would rather it took List[str] patterns instead, for matching against List[str] input. so you could do things like: pattern = ["foo", "?", "\", "?", "bar", "baz"] input = ["foo", "?", "bar", "baz"] # matches input = ["?", "bar", "baz"] # matches input = ["foo?barbaz"] # doesn't match bonus points if it also takes arbitrary objects: pattern = [None, True, False, "?"] input = [None, True] # matches input = [None, False] # doesn't match input = [None, True, False] #matches On 2020-09-28 8:10 p.m., Giang Le wrote:
participants (5)
-
2QdxY4RzWzUUiLuE@potatochowder.com
-
Giang Le
-
Marco Sulla
-
Oleg Broytman
-
Soni L.