REGEX to Select a line that contains an unmounted string

Asked

Viewed 262 times

1

I would like to select an entire row that contains a desired string. For example:

String: "BLUE LED should light"

text:

When pressing the button the BLUE LED should light up for 5 seconds according to the characteristics of the test.

I would like to select the entire line that contains the string "LED BLUE should light" through a Regex that can be used in Notepad++ or python. Could someone help me? Thank you!!

  • In the case of Notepad++, if you want to find a entire line (that is, do the matching whole row) if it contains the string LED AZUL, just use regular expression: ^.*LED AZUL.*$. The ^ indicates the beginning of the line and the $ indicates the end of the line. O .* indicates any character, in any quantity (between the beginning of the line and the BLUE LED, and then between the BLUE LED and the end of the line).

  • 1

    Thank you @Luizvieira !!

1 answer

2


With python it’s relatively easy, you don’t even need to use regex:

str_desejada = 'LED AZUL deve acender'
for linha in linhas:
    if str_desejada in linha:
        print('existe')

Regex:

import re

linha = 'Ao apertar o botão o LED AZUL deve acender por 5 segundos de acordo com as caracteristicas do teste.'
comp = re.compile('LED AZUL deve acender')
for linha in linhas:
    match = comp.search(linha)
    if match:
        print('existe')
  • Thanks Miguel for the help! Could you help me with the regex to find this case ae? Thank you!!

  • @Diegosanchesgarcia put on top, but for this specific case, without more information, I would opt for the first solution

  • Thank you Miguel!!

  • You’re welcome @Diegosanchesgarcia, I’m glad I helped

Browser other questions tagged

You are not signed in. Login or sign up in order to post.