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 pesadas", "El árbol ((VERB es)) grande, las hojas ((VERB)son) doradas y ((VERB)son) secas, los juegos del parque ((VERB)estan) algo oxidados y ((VERB)es) peligroso subirse a ellos"]

aux_list = []
for i_input_text in sentences_list:

    #separator_symbols = r'(?:(?:,|;|.|s+)s*ys+|,s*|;s*)'
    separator_symbols = r'(?:(?:,|;|.|)s*ys+|,s*|;s*)(?:[A-Z]|l[oa]s|la|[eé]l)'
    
    pattern = r"((VERB)s*w+(?:s+w+)*)"
    
    # Separar la frase usando separator_symbols
    frases = re.split(separator_symbols, i_input_text)
    
    aux_frases_list = []
    # Buscar el patrón en cada frase separada
    for i_frase in frases:
        verbos = re.findall(pattern, i_frase)
        if verbos:
            #print(f"Frase: {i_frase}")
            #print(f"Verbos encontrados: {verbos}")
            aux_frases_list.append(i_frase)
    aux_list = aux_list + aux_frases_list
    
sentences_list = aux_list
print(sentences_list)

How to make these separations without what is identified by (?:[A-Z]|l[oa]s|la|[eé]l) be removed from the following string after the split?

Using this code I am getting this wrong output:

['El coche ((VERB) es) rojo', ' bicicleta ((VERB)está) allí', ' monopatín ((VERB)ha sido pintado) de color rojo', ' camión también ((VERB)funciona) con cargas pesadas', ' hojas ((VERB)son) doradas y ((VERB)son) secas', ' juegos del parque ((VERB)estan) algo oxidados y ((VERB)es) peligroso subirse a ellos']

It is curious that the sentence "El árbol ((VERB es)) grande" directly dasappeared from the final list, although it should be

Instead you should get this list of strings:

["El coche ((VERB) es) rojo", "la bicicleta ((VERB)está) allí", "el monopatín ((VERB)ha sido pintado) de color rojo", "el camión también ((VERB)funciona) con cargas pesadas", "El árbol ((VERB es)) grande", "las hojas ((VERB)son) doradas y ((VERB)son) secas", "los juegos del parque ((VERB)estan) algo oxidados y ((VERB)es) peligroso subirse a ellos"]
Asked By: Matt095

||

Answers:

I’m taking a guess the splitter regex should be this:

(?:[,.;]?s*ys+|[,;]s*)(?=[A-Z]|l(?:[ao]s|a)|[eé]l)

https://regex101.com/r/jpWfvq/1

 (?: [,.;]? s* y s+ | [,;] s* )   # consumed
 (?=                                 # not consumed
    [A-Z] 
  | l
    (?: [ao] s | a )
  | [eé] l
 )

which splits on punctuation and y (ands, optional) at the boundarys
while maintaining a forward looking group of qualifying text without consuming them. And trimming leading whitespace as a bonus.

Answered By: sln