I am new to regex so please explain how you got to the answer. Anyway I want to know the best way to match input function from a separate python file. For example: match.py Now I want to match ONLY the input statement and replace it with a random number. I will do this in a separate file main.py. So
Tag: regex
Match everything except certain strings
I am trying to write python script to match a regex that can include everything which has two – and one . but I also want to exclude two strings from it. They are NIST-Privacy-v1.1 and NIST-CSF-v1.1 Here is my sample data: I started with a very simple regex which does the job of matching what I need but doesn’t
How to use the Python packaging library with a custom regex?
I’m trying to build and tag artifacts, the environment name gets appended at the end of the release, e.g.: 1.0.0-stg or 1.0.0-sndbx, none of them are PEP-440 compliance, raising the following error message: Using the packaging library I know I can access the regex by doing: However, my question is how can I customize the regex rule also to support
Regex for Alternating Numbers
I am trying to write a regex pattern for phone numbers consisting of 9 fixed digits. I want to identify numbers that have two numbers alternating for four times such as 5XYXYXYXY I used the below sample I tried the below pattern but it is not accurate can someone point out what i am doing wrong? Answer I would use:
Execute f-string in function
I have a and want to replace all tokens starting with with a new token I wrote a function: If I execute the lines separately it works. But the function itself doesn’t work. I’d expect How can I “exec” f-string in a function? Answer You are overcomplicating this. Simply reassign x: But it’s probably easier to rewrite the function similar
Add a space after a word if it’s at the beginning of a string or if it’s after one or more spaces, and at the same time it must be at end or before n
How to obtain this outputs from those inputs? Note that for examples 4, 5, 6 and 7 the regex should not make any changes, since after the word there is already a space placed, or because in the case of “uno”, the word “un” is not at the end of the sentence, or in the case of “treinta yun” the
regex whole string match between numbers
I want to extract a whole word from a sentence. Thanks to this answer, I can get whole words in cases like: where symbols next to the word don’t bother. However if there’s a number it doesn’t find the word. How should I modify the expression to match cases where there’s a number next to the word? Like: Answer Can
python re.split function, how do I return the full character set?
I’m trying to use a regex pattern split this string into chunks seperated by any character. This prints [”, ’12’, ’56’, ‘1’] How do I use the split function to have it output the whole string, delimited by any character? IE [‘a12’, ‘b56’, ‘c1’] Answer Try to use re.findall instead re.split (regex101): Prints:
How to remove white space in between ascii and nonascii chars?
For example: I want to find at least 3 ascii chars, followed by a space, then followed by a nonascii char, and replace the white space with empty string. My code has two issues: How to write the replacement string for (s)? How to make it also work for the reverse order of s2?: [^a-zA-Z0-9] Answer Put the strings that
Regex to match a list of one or more comma-separated words, unless the string ends in a comma
I have written the following regex long time ago that must match at least 3 words and works in both Latin and Cyrillic characters : regex = ‘([^ ,;d]{2,}[ ,;]{1,}){2,}[^ ,;d]{2,}’ I would like to rewrite it to match hello but fail to match hello, because of the comma. However, I would still like it to match hello, and, more,