regex

Python re Regular Expression for repeated, but not necessarily sequential digits

Python re Regular Expression for repeated, but not necessarily sequential digits Question: I want an RE that looks something like ‘5[0-9]2[0-9]5’ But I need the two [0-9] wildcards to match. So ‘50205’, ‘51215’, ‘52225’, etc should all match but ‘51265’ and ‘53285’ should not. Is there a way to do this? I can use a …

Total answers: 1

re.search for first (of two) dates in filenames

regex formatting on a complex file name Question: I struggled to properly format regex to pull the first date in the following file name: TEST_2022-03-04-05-30-20.csv_parsed.csv_encrypted.csv I ran the following and expected to extract the first date in each file name formatted as 2022-03-04 date = re.search(‘b(d{4}-d{2}-d{2}).’, filename) I obtained the following error on the re.search …

Total answers: 2

Remove entire array based on single item on list using regex

Remove entire array based on single item on list using regex Question: I have several list of lists (obtained from a for loop). Each one is composed like following: [[‘8.761,00’, ‘67.512,00’, ‘0,00’, ”, ”], [None, ”, ”, ”, ”], [”, ‘Dovuto’, ‘Pagato’, ‘Rimborsato’, ‘Debito/Credito’], [‘Soggettivo 15%’, ‘1.314,15’, ‘1.314,15’, ‘0,00’, ‘0,00’], [‘Integrativo 4%’, ‘2.700,48’, ‘2.700,48’, ‘0,00’, …

Total answers: 3

Extract with multiple Patterns

Extract with multiple Patterns Question: Having an issue that maybe some help me with. I am trying to extract two patterns from a string and place them in another column. It’s extracting the first string fine but I am missing some in getting the second one there. Here’s the string. jobseries[‘New Column’] = jobseries[‘Occupation’].str.extract(‘(GS-d+)(|)(WG-d+)’).fillna(”) The …

Total answers: 1

regex that matches simple arithmetic expressions

regex that matches simple arithmetic expressions Question: i have a solution, but the only problem is that for example "7=7=7" is matched and that should not be the case. ^[+-]?d+([/*+-]d+)*([/*+-]*=(?:[+-]?d+([/*+-]d+)*)+)*$ see below of what is matched and not these are matched and that is correct 456+5 0 0+0 5=0 1589+232 55+2 5+55 545454545 -12*53+1-2/5 +1+2+3=-5*2/3 …

Total answers: 2

How to rename images with specific pattern?

How to rename images with specific pattern? Question: I have this image folder as shown below that has repated charchter name A I want only keep one letter A with rest of numbers + ext the input : input_folder –| |— imgs — |– A_0.jpg |– A_A_A_1.jpg |– A_A_2.jpg |– A_A_A_A_3.jpg |– A_4.jpg ……… I …

Total answers: 1

create a regex that knows balanced parenthesis with maximum depth of 5

create a regex that knows balanced parenthesis with maximum depth of 5 Question: I have a problem with a regex, it is supposed to match if the depth is between 1 or 5, for example it should match with “()()()”, “((((()))))”, “(()((()))())” and not match with “())()”, “(((((())))))” och “(x)”. I have this pattern = …

Total answers: 3

Ways to speedup regex and make it faster

Ways to speedup regex and make it faster Question: Is there a way to speedup this code regex code? The file is really large and will not open in excel because of size. import regex as re path = "C:/Users/…/CDPH/" with open(path + ‘Thefile.tab’) as file: data = file.read() # replace all space bars between …

Total answers: 2

Regex whitelisted url lets blocked urls through on the same line in message

Regex whitelisted url lets blocked urls through on the same line in message Question: So I have a regex expression which blocks URLs in a message, but I want to whitelist the site’s URL. currently it works with any prefix like HTTP://www.example.com and with www.example.com/support/how-do-i-setup-this but if I put another URL behind this then it …

Total answers: 1