All Questions
11 questions
1
vote
2
answers
90
views
Regex does or does not give an error depending on which REPL is used
Consider the following Python code using the regex library re
import re
re.compile(rf"{''.join(['{c}\\s*' for c in 'qqqq'])}")
I have run it in two different REPLs:
https://www....
0
votes
3
answers
478
views
Execute f-string in function
I have a
string = 'long company name with technologies in it'
and want to replace all tokens starting with
search_string ='techno'
with a new token
replace_string = 'tech'.
I wrote a function:
def ...
1
vote
1
answer
245
views
Using f-string and raw string at same time
I have a dataframe like this:
p q
0 jdkdn 01JAN2020
1 01JAN2020 hdk789dj
2 783i3 01FEB2020
I am trying to replace 01JAN2020 by 01-01-2020, basically alphabetical ...
1
vote
1
answer
47
views
create a function that returns a tuple of regex expressions
I have several different modules with similar regex expressions.
In module A, I have:
string_to_find = rf'([^_A-z]{variable_name}\()(.+?)(,\s?)(.+?)(,|\))'
string_to_replace = r'\1\4\3\2\5'
In module ...
0
votes
1
answer
644
views
python f-string include all numbers except 0 while making a file list
I want to make a list of files with extend() while ignoring any file name ending with 0 as in _file0.h5. I have this line for concatenating all the files into a list
data_files_0.extend(sorted(glob(f&...
-1
votes
1
answer
470
views
How to exclude the bracketed characters in a Python f-string using regex?
Recently, I have been creating an editor in Python 3.7.6 (using tkinter), I created the following syntax for highlighting single, double and triple quotes but I want to exclude all the characters ...
5
votes
1
answer
3k
views
Combining f-string with raw string to be used inside regex gives SyntaxError; ValueError or wrong result
I have a string here :
s0 = 'Ready1 Origin1 Destination1 Type1 Rate1 Phone1 # Pro1 #'
and the following variable being calculated like this :
is_head = ...
1
vote
2
answers
794
views
use a dictionary for word replacement with regex in python
I am trying to write a bit of code that will use regex to expand abbreviations in a text file to full words but not replace all instances of the abbreviation text.
I can’t figure out what goes in ...
2
votes
0
answers
664
views
Recursive regular expressions for defining syntax using 'fr' strings
When creating grammar rules for a language I am making, I would like to be able to check syntax and step through it instead of the current method which often will miss syntax errors.
I've started off ...
4
votes
1
answer
7k
views
How to format f-strings with regex expressions?
I have a few strings that were originally concatenated with plus signs and included regex strings. Here's an example:
"Level 4: " + re.sub(r"(\w)([A-Z])", r"\1 \2", talents[1]) + "\n\n"
But, I've ...
53
votes
1
answer
47k
views
how do I use f-string with regex in Python
This code works if I use raw strings only. However, as soon as I add f to r it stops working.
Is there a way to make f-strings work with raw strings for re?
import re
lines = '''
04/20/2009; 04/...