regex

pandas/regex: Remove the string after the hyphen or parenthesis character (including) carry string after the comma in pandas dataframe

pandas/regex: Remove the string after the hyphen or parenthesis character (including) carry string after the comma in pandas dataframe Question: I have a dataframe contains one column which has multiple strings separated by the comma, but in this string, I want to remove all matter after hyphen (including hyphen), main point is after in some …

Total answers: 2

Extract date from string in date format, add n number of days. to then replace with that modified data another substring within the original string

Extract date from string in date format, add n number of days. to then replace with that modified data another substring within the original string Question: import re, datetime, time input_text = "tras la aparicion del objeto misterioso el 2022-12-30 visitamos ese sitio nuevamente revisando detras de los arboles pero recien tras 3 dias ese …

Total answers: 1

python re unterminated character set at position 0

python re unterminated character set at position 0 Question: CODE: import re inp=input() tup=tuple(map(str,inp.split(‘,’))) i=0 while i<len(tup): x=tup[i] a=re.search("[0-9a-zA-Z$#@",x) if a!="None": break else: i=i+1 if a!="None" and len(tup[i])>=6 and len(tup[i])<=12: print(tup[i]) else: print("invalid") INPUT: [email protected],a F1#,2w3E*,2We3345 ERROR: unterminated character set at position 0 Asked By: hari || Source Answers: The error stems from the invalid …

Total answers: 2

I want to convert multiple characters to Python regular expressions

I want to convert multiple characters to Python regular expressions Question: I want to convert only numbers in this str "ABC234TSY65234525erQ" I tried to change only areas with numbers to the * sign This is what I wanted "ABC*TSY*erQ" But when I actually did it, it came out like this "ABC***TSY********erQ" How do I change …

Total answers: 2

Regular expression to extract text in python

Regular expression to extract text in python Question: I am new using the re library and I would like to know if somebody knows how to extract the following text: Initial ‘[p]I am a test paragraph[/p]’ Output I am a test paragraph I tried to use the following line : text = ‘[p]I am a …

Total answers: 2

Negative lookbehind + Non capturing group

Negative lookbehind + Non capturing group Question: (?<!")https://t.me/(c)?/?([+a-zA-Z0-9]+)/?([0-9]*)? I want to find all telegram links without quotation marks (") but I don’t want the leading negative lookbehind to be a group, how can I do this? I tried the following but it didn’t work. This code works but i want the initial negative lookbehind not …

Total answers: 1

Comma separated number after specific substring in middle of string

Comma separated number after specific substring in middle of string Question: I need to extract a sequence of coma separated numbers after specific substring. When the substring is in the beginning of the string it works fine, but not when its in the middle. The regex ‘Port’: .([0-9]+) works fine with the example below to …

Total answers: 3

Regular expression to capture n words after pattern that do not contain that pattern

Regular expression to capture n words after pattern that do not contain that pattern Question: I’m trying to write a regular expression that captures n words after a pattern, which was answered in this question, except I want the search to keep going for another n words if it encounters that pattern again. For example, …

Total answers: 1

Python regex to get the closest match without duplicated content

Python regex to get the closest match without duplicated content Question: What I need I have a list of img src link. Here is an example: https://studiocake.kiev.ua/wp-content/webpc-passthru.php?src=https://studiocake.kiev.ua/wp-content/uploads/photo_2020-12-27_12-18-00-2-333×444.jpg&nocache=1 https://studiocake.kiev.ua/wp-content/webpc-passthru.php?src=https://studiocake.kiev.ua/wp-content/uploads/IMG_4945-333×444.jpeg&nocache=1 https://studiocake.kiev.ua/wp-content/webpc-passthru.php?src=https://studiocake.kiev.ua/wp-content/uploads/tri-shokolada.png&nocache=1 I need get the following result: studiocake.kiev.ua/wp-content/uploads/photo_2020-12-27_12-18-00-2-333×444.jpg studiocake.kiev.ua/wp-content/uploads/IMG_4945-333×444.jpeg studiocake.kiev.ua/wp-content/uploads/tri-shokolada.png Problem I use the following regex: studiocake.kiev.ua.*(jpeg|png|jpg) But it doesn’t work the way I need. Instead of …

Total answers: 3

Pandas REGEX not returning expected results using "extract"

Pandas REGEX not returning expected results using "extract" Question: I am attempting to use REGEX to extract connection strings from blocks of text in a pandas dataframe. My REGEX works on REGEX101.com (see Screenshot below). Link to my saved test here: https://regex101.com/r/ILnpS0/1 When I try to run the REGEX in a Pandas dataframe, I don’t …

Total answers: 1