Regue
Regue

Reputation: 43

Select in regex the first sentece after question mark

I need to select with regex the first sentence (all text to the first dot) of each question. And then in repleace I add $1 to put this tag

I try this but select whole text, not only the first sentence.

^[a-zA-Z].*

I have an example:

Cómo se hace para formatear una PC? Haz click sobre el botón de inicio. Selecciona la rueda dentada para acceder a Ajustes del Sistema. Pulsa sobre Actualización y Seguridad. En la pestaña de Restaurar, haz click en Comenzar o Empezar. En la ventana que se abre, selecciona Restablecer Ajustes de Fábrica.

¿Cómo formatear mi PC windows 10 a estado de fábrica? Haz click sobre el botón de inicio. Selecciona la rueda dentada para acceder a Ajustes del Sistema. Pulsa sobre Actualización y Seguridad. En la pestaña de Restaurar, haz click en Comenzar o Empezar. En la ventana que se abre, selecciona Restablecer Ajustes de Fábrica.

And this is what I need.

Cómo se hace para formatear una PC? Haz click sobre el botón de inicio. Selecciona la rueda dentada para acceder a Ajustes del Sistema. Pulsa sobre Actualización y Seguridad. En la pestaña de Restaurar, haz click en Comenzar o Empezar. En la ventana que se abre, selecciona Restablecer Ajustes de Fábrica.

¿Cómo formatear mi PC windows 10 a estado de fábrica? Haz click sobre el botón de inicio. Selecciona la rueda dentada para acceder a Ajustes del Sistema. Pulsa sobre Actualización y Seguridad. En la pestaña de Restaurar, haz click en Comenzar o Empezar. En la ventana que se abre, selecciona Restablecer Ajustes de Fábrica.

I try a lot of features but I'm so bad with regex and I couldn't select that.

Upvotes: 0

Views: 39

Answers (2)

Alex Bright
Alex Bright

Reputation: 21

You may try this pattern, this won't include the question mark and dot, and uses lazy to only put bold marks around the first sentence:

Replace(r"(?<=\?)(.*?)(?<=\.)","<b>\1<b>")

Upvotes: 0

JRiggles
JRiggles

Reputation: 6790

Try this pattern (?<=\? )[^\.]* - see here for a breakdown of the RegEx.

If you also need to capture the period at the end of the sentence, use this: (?<=\? )[^\.]*\. (note the addition of \. at the end)

Upvotes: 1

Related Questions