Fim da linha - adicione um tubo |

Fim da linha - adicione um tubo |

Alguém pode explicar como no final de cada linha coloco um pipe com regex?

Usando localizar e substituir no bloco de notas++

Estou tentando colocarcontent |

Saúde!

Responder1

Se você quiser apenas adicionar uma barra vertical no final de cada linha, basta usar este regex 'find':

$

(O símbolo do dólar corresponde ao final de uma linha no regex)

E esta 'substituição':

|

Certifique-se de ativar a localização de expressões regulares.

Responder2

Encontre o que:(.*)

Substituir com:$1|

Isso usaagrupamento, $1basicamente diz inserir o que foi encontrado entre parênteses e, em seguida, adicionar o tubo no final. O .irá capturar qualquer caractere, exceto determinados espaços em branco, como novas linhas, que são ideais nesta situação. Os *meios permitem que 0 ou mais caracteres sejam capturados com o.

Isso é escalonável, portanto, se você deseja capturar apenas determinadas linhas, por exemplo, linhas que contêm teste:

Encontre o que:(.*test.*)

Substituir com:$1|

Portanto, se você inseri-los e clicar em "Substituir tudo", você terá barras verticais no final de cada linha que corresponde à expressão regular.

Responder3

Resposta alterada.
Eu usaria isso. Eu trabalho no modo de linha única ou multilinha.
Não tenho certeza de qual bloco de notas está disponível (ou seja, pesquisar/substituir, localizar/substituir, etc.).
Procure isto: (?=\r\n|\n|\r|$)
e insira (substitua) isto: |

Apenas algumas notas sobre o assunto complicado do que realmente é $ metachar.
Não é tão fácil como deveria ser e o Docs deixa muito a desejar.

De qualquer forma, aqui está minha opinião sobre isso -

 # Regular Expression Docs:
 # Metacharacter  $ 
 # Match the end of the line (or before newline at the end)
 # ** This really is misworded, it really means:
 #
 #    In single line mode,
 #      In two separate matches (in global context) 
 #         Match before and after a newline at the end of a string if there is a newline,
 #      OR, Match the end of the string only.
 #
 #    In multi-line mode,
 #         Match before OR after a newline at the end of a line or string,
 #         but not both.
 #
 # ---------------------------------------------
 # The above explanation is conditional upon the qualifying 
 # subexpressions surrounding the $ metachar
 # ---------------------------------------------

 # /$/g  Single line mode:
 # Matches before newline (if there is one) AND end of string (always this)

 print "=== /\$/g ===============\n";
    $str = "0  ";          $str =~ s/$/|/g;  print "'$str'\n---\n";
    $str = "1  \n";        $str =~ s/$/|/g;  print "'$str'\n---\n";
    $str = "2  \n\n";      $str =~ s/$/|/g;  print "'$str'\n---\n";
    $str = "3  \n\n\n";    $str =~ s/$/|/g;  print "'$str'\n---\n";
    $str = "4  \n\n\n\n";  $str =~ s/$/|/g;  print "'$str'\n\n";

 # /$/mg   Multi-line mode:
 # Matches before each newline (if there is one) OR end of string (not both)

 print "===  /\$/mg ===============\n";
    $str = "0  ";          $str =~ s/$/|/mg;  print "'$str'\n---\n";
    $str = "1  \n";        $str =~ s/$/|/mg;  print "'$str'\n---\n";
    $str = "2  \n\n";      $str =~ s/$/|/mg;  print "'$str'\n---\n";
    $str = "3  \n\n\n";    $str =~ s/$/|/mg;  print "'$str'\n---\n";
    $str = "4  \n\n\n\n";  $str =~ s/$/|/mg;  print "'$str'\n\n";

 # /(?=\r\n|\n|\r|$)/g   Single line mode:
 # Parsing the expression for //m Multi-line mode,
 # Equivalent of /$/m  can now be run in Single line mode:
 # This is What /$/m  probably really is.
 # Matches before each newline (if there is one) OR end of string (not both)

 print "=== /(?=\\r\\n|\\n|\\r|\$)/g ==============\n";
    $str = "0  ";          $str =~ s/(?=\r\n|\n|\r|$)/|/g;  print "'$str'\n---\n";
    $str = "1  \n";        $str =~ s/(?=\r\n|\n|\r|$)/|/g;  print "'$str'\n---\n";
    $str = "2  \n\n";      $str =~ s/(?=\r\n|\n|\r|$)/|/g;  print "'$str'\n---\n";
    $str = "3  \n\n\n";    $str =~ s/(?=\r\n|\n|\r|$)/|/g;  print "'$str'\n---\n";
    $str = "4  \n\n\n\n";  $str =~ s/(?=\r\n|\n|\r|$)/|/g;  print "'$str'\n\n";

 # /(?=\r\n|\n|\r|$)/mg   Multi-line mode:
 # Exact same output.

 print "=== /(?=\\r\\n|\\n|\\r|\$)/mg ==============\n";
    $str = "0  ";          $str =~ s/(?=\r\n|\n|\r|$)/|/mg;  print "'$str'\n---\n";
    $str = "1  \n";        $str =~ s/(?=\r\n|\n|\r|$)/|/mg;  print "'$str'\n---\n";
    $str = "2  \n\n";      $str =~ s/(?=\r\n|\n|\r|$)/|/mg;  print "'$str'\n---\n";
    $str = "3  \n\n\n";    $str =~ s/(?=\r\n|\n|\r|$)/|/mg;  print "'$str'\n---\n";
    $str = "4  \n\n\n\n";  $str =~ s/(?=\r\n|\n|\r|$)/|/mg;  print "'$str'\n\n";

Saída >>

 === /$/g ===============
 '0  |'
 ---
 '1  |
 |'
 ---
 '2
 |
 |'
 ---
 '3

 |
 |'
 ---
 '4


 |
 |'

 ===  /$/mg ===============
 '0  |'
 ---
 '1  |
 |'
 ---
 '2  |
 |
 |'
 ---
 '3  |
 |
 |
 |'
 ---
 '4  |
 |
 |
 |
 |'

 === /(?=\r\n|\n|\r|$)/g ==============
 '0  |'
 ---
 '1  |
 |'
 ---
 '2  |
 |
 |'
 ---
 '3  |
 |
 |
 |'
 ---
 '4  |
 |
 |
 |
 |'

 === /(?=\r\n|\n|\r|$)/mg ==============
 '0  |'
 ---
 '1  |
 |'
 ---
 '2  |
 |
 |'
 ---
 '3  |
 |
 |
 |'
 ---
 '4  |
 |
 |
 |
 |'

informação relacionada