regex

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

How can I remove all unneeded whitespaces in string but keep symbols like 'n'?

How can I remove all unneeded whitespaces in string but keep symbols like 'n'? Question: I have such a string: s = ‘Hello nWorld!nToday is a wonderful day’ And I need to get this: ‘Hello nWorld!nToday is a wonderful day’ I tried to use split and join like: ‘ ‘.join(‘Hello nWorld!nToday is a wonderful day’.split()) …

Total answers: 3

Python Regex to extract text between numbers

Python Regex to extract text between numbers Question: I’d like to extract the text between digits. For example, if have text such as the following 1964 ORDINARY shares EXECUTORS OF JOANNA C RICHARDSON 100 ORDINARY shares TG MARTIN C MARTIN 7500 ORDINARY shares ARCO LIMITED I want to produce a list of 3 elements, where …

Total answers: 2

how to extract only letter from a string mixed with numbers with python

how to extract only letter from a string mixed with numbers with python Question: I have this table in my dataframe, the char column is mixed either with letters only, numbers only or the combination between letters and numbers. char count 123 24 test 25 te123 26 test123 26 I want to extract only the …

Total answers: 3

How to match a changing pattern in python?

How to match a changing pattern in python? Question: So I have a collection of lyrics from different artists, but in the middle of all the lyrics there is always an advertisement I want to remove. It looks like this: ‘lyric lyric See John Mayer LiveGet tickets as low as $53 lyric lyric’ More generally, …

Total answers: 1

Python regex to remove string which may contain additional character

Python regex to remove string which may contain additional character Question: I’ve got a string in python that sometimes starts with either {txt – or {txt. These do not always appear at the start of the string, but if they do, I want to remove them. I know I can do it like this: string …

Total answers: 2

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