regex-group

Reuse named group across multiple patterns in Python involving `|` operator with single compilation

Reuse named group across multiple patterns in Python involving `|` operator with single compilation Question: I plan to match the string(one line) with any one of the patterns. Pattern1: fname lname Pattern2: lname,fname Example String(s): Frank Delo Delo,Frank groupdict() Output should return the same for both the strings {"fname":"Frank", "lname":"Delo" } Here’s what I tried …

Total answers: 1

Regex Expression not spanning newlines

Regex Expression not spanning newlines Question: I have a string of data as a result of another working regex: pattern = re.compile(r’CALL|d*|.*n*((?:n.*)+?)(?=nCALL|Z)’,re.MULTILINE) matches = pattern.finditer(text) list_dataframe = [] audit_data = [] counter = 0 for match in matches: while counter < 1: small_string = match.group(0) print(small_string) print(‘end small string n’) pattern1 = re.compile(r’BENCHMARK|Assigned|(?:.*)(?=|Assigned||Z)’,re.MULTILINE) # assignments_iterator …

Total answers: 1

Python regex search and identify the first occurence

Python regex search and identify the first occurence Question: I have a sql string and I need to identify the first occurrence of the database and table name from the sql. sql = ‘select col1, col2, "base" as db_name, "employee" as table_name from base.employee where id is not NULL union select col1, col2, "base" as …

Total answers: 3

How to find nested patterns within a string, and merge them into one using a regex reordering of the string?

How to find nested patterns within a string, and merge them into one using a regex reordering of the string? Question: import re #example input string: input_text = "here ((PERS)the ((PERS)Andys) ) ((PERS)assása asas) ((VERB)asas (asas)) ((PERS)saasas ((PERS)Asasas ((PERS)bbbg gg)))" def remove_nested_pers(match): # match is a re.Match object representing the nested pattern, and I want …

Total answers: 1

How to capture all substrings that match this regex pattern, which is based on a repeat range of 2 or more consecutive times?

How to capture all substrings that match this regex pattern, which is based on a repeat range of 2 or more consecutive times? Question: import re input_text = "((PERS)Marcos) ssdsdsd sdsdsdsd sdsdsd le ((VERB)empujé) hasta ((VERB)dejarle) en ese lugar. A ((PERS)Marcos) le ((VERB)dijeron) y luego le ((VERB)ayudo)" input_text = re.sub(r"((PERS)((?:ws*)+))s*((?!el)w+s+){2,}(le)", lambda m: print(f"{m[2]}"), input_text, flags …

Total answers: 1

Why does this regex pattern freeze and get stuck infinitely?

Why does this regex pattern freeze and get stuck infinitely? Question: import re input_text = "Creo que ((PERS)el viejo gabinete) estan en desuso, hay que hacer algo con él. ya que él aún es útil. Él sirve para tareas de ofimatica. ((PERS)el viejo mouse) es algo comodo, aunque el clic de él falla." personal_article_with_subject = …

Total answers: 1

How to perform string separations using regex as a reference and that a part of the used separator pattern is not removed from the following string?

How to perform string separations using regex as a reference and that a part of the used separator pattern is not removed from the following string? Question: import re sentences_list = ["El coche ((VERB) es) rojo, la bicicleta ((VERB)está) allí; el monopatín ((VERB)ha sido pintado) de color rojo, y el camión también ((VERB)funciona) con cargas …

Total answers: 1