regex

python3 regex pattern to separate items on a line

python3 regex pattern to separate items on a line Question: I don’t know regex … I have a file with lines like this: 1143 296 ‘D:\ssTEST\TEST_VIDS IMAGES\2022-11-Tasmania renamed\01\2022_11_08_03_49_03_000000_rot_090_1080x1920__20221108_144850.mp4’ 1426 320 ‘D:\ssTEST\TEST_VIDS IMAGES\2022-11-Tasmania renamed\01\2022_11_08_03_49_22_000000_rot_090_1080x1920__20221108_144908.mp4’ 1733 319 ‘D:\ssTEST\TEST_VIDS IMAGES\2022-11-Tasmania renamed\01\2022_11_08_03_49_45_000000_rot_090_1080x1920__20221108_144932.mp4’ What regex string can separate parts of a line into integer_1, integer2, string_without_quotes ? ChatGPT has had …

Total answers: 2

Match whole word in string including special characters

Match whole word in string including special characters Question: I am aware of multiple existing answers that suggest: def contains(string, word): return bool(re.search(rf"b{word}b", string)) But this pattern gives special treatment to alphanumeric character. For examples, contains("hello world!", "world!") returns False while contains("hello world!", "world") returns True. I need a more ‘naive’ search pattern, one that …

Total answers: 1

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