RE

Mask multiple sensitive data using re.sub?

ぐ巨炮叔叔 提交于 2021-02-11 15:19:51
问题 I would like to mask several values ​​in a string. This call works for a single value as expected. message = "my password=secure and my private_key=securekey should not be logged." message = re.sub(r"(?is)password=.+", "password=xxxx", str(message)) What does the regular expression have to look like so that I can mask multiple values from a dictionary? d = {"password": "xxxx", "private_key": "zzzz"} message = re.sub(r"(?is)\w=.+", lambda m: d.get(m.group(), m.group()), message) Is it also

Mask multiple sensitive data using re.sub?

半城伤御伤魂 提交于 2021-02-11 15:16:42
问题 I would like to mask several values ​​in a string. This call works for a single value as expected. message = "my password=secure and my private_key=securekey should not be logged." message = re.sub(r"(?is)password=.+", "password=xxxx", str(message)) What does the regular expression have to look like so that I can mask multiple values from a dictionary? d = {"password": "xxxx", "private_key": "zzzz"} message = re.sub(r"(?is)\w=.+", lambda m: d.get(m.group(), m.group()), message) Is it also

Python - Fast count words in text from list of strings and that start with

和自甴很熟 提交于 2021-02-08 02:40:30
问题 I know that similar questions have been asked several times, but my problem is a bit different and I am looking for a time-efficient solution, in Python. I have a set of words, some of them end with the "*" and some others don't: words = set(["apple", "cat*", "dog"]) I have to count their total occurrences in a text, considering that anything can go after an asterisk ("cat*" means all the words that start with "cat"). Search has to be case insensitive. Consider this example: text = "My cat

Python - Fast count words in text from list of strings and that start with

南笙酒味 提交于 2021-02-08 02:40:14
问题 I know that similar questions have been asked several times, but my problem is a bit different and I am looking for a time-efficient solution, in Python. I have a set of words, some of them end with the "*" and some others don't: words = set(["apple", "cat*", "dog"]) I have to count their total occurrences in a text, considering that anything can go after an asterisk ("cat*" means all the words that start with "cat"). Search has to be case insensitive. Consider this example: text = "My cat

Python - Fast count words in text from list of strings and that start with

本秂侑毒 提交于 2021-02-08 02:40:13
问题 I know that similar questions have been asked several times, but my problem is a bit different and I am looking for a time-efficient solution, in Python. I have a set of words, some of them end with the "*" and some others don't: words = set(["apple", "cat*", "dog"]) I have to count their total occurrences in a text, considering that anything can go after an asterisk ("cat*" means all the words that start with "cat"). Search has to be case insensitive. Consider this example: text = "My cat

Extract all substrings between two markers

两盒软妹~` 提交于 2020-08-10 23:02:27
问题 I have a string: mystr = "&marker1\nThe String that I want /\n&marker1\nAnother string that I want /\n" What I want is a list of substrings between the markers start="&maker1" and end="/\n" . Thus, the expected result is: whatIwant = ["The String that I want", "Another string that I want"] I've read the answers here: Find string between two substrings [duplicate] How to extract the substring between two markers? And tried this but not successfully, >>> import re >>> mystr = "&marker1\nThe

Extract all substrings between two markers

[亡魂溺海] 提交于 2020-08-10 23:01:05
问题 I have a string: mystr = "&marker1\nThe String that I want /\n&marker1\nAnother string that I want /\n" What I want is a list of substrings between the markers start="&maker1" and end="/\n" . Thus, the expected result is: whatIwant = ["The String that I want", "Another string that I want"] I've read the answers here: Find string between two substrings [duplicate] How to extract the substring between two markers? And tried this but not successfully, >>> import re >>> mystr = "&marker1\nThe