regex

python regex not capturing variables, but regex working

python regex not capturing variables, but regex working Question: I am trying to create a data frame with variables: bidder_rank, bidder_id, bid_total, bidder_info. I have created a regex pattern, which seems to work on regex101. However, the Python script has been breaking for a reason I cannot figure out. # imports import os import pandas …

Total answers: 2

RegEx Look Ahead/Look Behind when the look behind pattern is different

RegEx Look Ahead/Look Behind when the look behind pattern is different Question: First off, my apologies for posting this ugly, long sample, but it’s all I could muster. I’m trying to get the IPs for both the source of the malware and the host. My pattern works well with the host, but it breaks when …

Total answers: 2

Search string that contains WORD with W or ^ before and W or $ after

Search string that contains WORD with W or ^ before and W or $ after Question: How to simplify following regular expression re.search(f’W{word}W’, text) or re.search(f’^{word}W’, text) or re.search(f’W{word}$’, text) or word == text i.e. return True for any string that contains word with W or ^ before and W or $ after. Variants re.search(f'[^W]{word}[W$]’, …

Total answers: 1

Regex for finding a sequence

Regex for finding a sequence Question: I have a string consisting of Latin letters and I need an regular expression that will find a sequence that does not contain [ABC][ABC]. For example, I have the string "AGSHDGSGBCHAHSNABHJDKOCA" and all matches will be "AGSHDGSGB", "CHAHSNA", "BHJDKOC", "A" I tried using (?!.*[ABC][ABC]).+ but when i used the …

Total answers: 1

Is it a way to capture text as 'internal variables' in regex?

Is it a way to capture text as 'internal variables' in regex? Question: So i have these string test1string2 , test2string2 and test3string3. Regex "test/dstring/d" would capture the three of them, but is there a way to write a regex that will capture only the second and third strings? Sort of: capture "test" followed by …

Total answers: 1

Why I got KeyError in loop "for" with regular expressions?

Why I got KeyError in loop "for" with regular expressions? Question: I got pandas.Series with few values. money = pd.Series(df_t[‘Сокращенное наименование ‘].unique()) 0 USDCNY_TOM 1 USDRCNY_TOD dtype: object My regular expression: m_trim = re.compile(r’_TOM$|_TOD$’) When I run this code, it’s works. m_trim.sub(”, money[0]) Result is: ‘USDCNY’. But then I trying to make loop: for m …

Total answers: 1

Trouble with lookbehind and lookahead

Trouble with lookbehind and lookahead Question: I’m having a hard time trying to get this simple RegEx to work. I need to capture the message "Windows Event Logs Cleared" or any other message that might be in that position. text = """2023-04-05 / 15:53:58 104 Windows Event Logs Cleared 21 low SRVR3 – j.smith 1 …

Total answers: 2

Excluding certain string using regex in python

Excluding certain string using regex in python Question: I would like to apply regex to the below code such that I remove any string that appears between a comma and the word ‘AS’. Select customer_name, customer_type, COUNT(*) AS volumenFROM tablenGROUP BY customer_name, customer_typenORDER BY volume DESCnLIMIT 10 Expected output: Select customer_name, customer_type, volumenFROM tablenGROUP BY …

Total answers: 2

Creating labels based on partial string matches in Python

Creating labels based on partial string matches in Python Question: I have an index column that’s leading 2 or 3 characters indicating a category I’d like to create labels for. Consider the following data: Index NDP2207342 OC22178098 SD88730948 OC39002847 PTP9983930 NDP9110876 with a desired output of: Index Labels NDP2207342 NCAR OC22178098 OCAR SD88730948 SDAR OC39002847 …

Total answers: 2

How to use pd.melt to unpivot a dataframe where columns share a prefix?

How to use pd.melt to unpivot a dataframe where columns share a prefix? Question: I’m trying to unpivot my data using pd.melt but no success so far. Each row is a business, and the data contains information about the business and multiple reviews. I want my data to have every review as a row. My …

Total answers: 3