Extrai e exibe apenas o ano de cada linha no Notepad ++ usando regex

2

Eu tenho strings como essa

hack SIGN (2005) g$
5 Cm Per Second - Makoto Shinkai Collection (2007)
Abenobashi (2002) gd
Ai City - La Notte Dei Cloni (1986) dfg
AIKA (1997)
Anna Dai Capelli Rossi (1979) £$"£

Eu quero mostrar no Notepad ++

2005
2007
2002
1986
1997
1979

Eu uso esse regex mas parece que não funciona bem

ENCONTRAR:

\(\b(19|20)\d{2}\b\)

SUBSTITUIR

r\n

Mas me retorne um texto assim

hack SIGN r
2020 g$
5 Cm Per Second - Makoto Shinkai Collection r
2020
Abenobashi r
2020 gd
Ai City - La Notte Dei Cloni r
1919 dfg
..

Portanto, este regex não funciona como esperado

    
por Super Sonic 06.08.2018 / 21:53

2 respostas

2

Siga as instruções abaixo ao pressionar Ctrl + H de Notepad ++ para combinar um grupo de números de 4 dígitos por cada linha e imprimir apenas os caracteres, dando-lhe os resultados esperados.

  1. Encontre o que: ^.*?(\d{4}+).*$

    enter image description here

  2. Substitua por: $1

  3. Modo de pesquisa: Regular expression
  4. Pressione Substituir tudo

Resultados

2005
2007
2002
1986
1997
1979

Maisrecursos

How to use regular expressions in Notepad++

Anchors

Anchors match a position in the line, rather than a particular character.

^

This matches the start of a line (except when used inside a set, see above).

$

This matches the end of a line.

Ranges or kinds of characters

[^...]

The complement of the characters in the set.

Single-character matches

., \c

Matches any character. If you check the box which says ". matches newline", the dot will indeed do that, enabling the "any" character to run over multiple lines. With the option unchecked, then . will only match characters within a line, and not the line ending characters (\r and \n)

Multiplying operators

*

This matches 0 or more instances of the previous character, as many as it can. For example, Sa*m matches Sm, Sam, Saam, and so on.

*?

Zero or more of the previous group, but minimally: the shortest matching string, rather than the longest string as with the "greedy" * operator. Thus, m.*?o applied to the text margin-bottom: 0; will match margin-bo, whereas m.*o will match margin-botto.

{n}

Matches n copies of the element it applies to.

+

This matches 1 or more instances of the previous character, as many as it can.

Groups

(...)

Parentheses mark a subset of the regular expression. The string matched by the contents of the parentheses ( ) can be re-used as a backreference or as part of a replace operation; see Substitutions, below.

Groups may be nested.

(?<some name>...), (?'some name'...),(?(some name)...)

Ranges or kinds of characters

\d

A digit in the 0-9 range, same as [[:digit:]].


Substitutions

$n, ${n}, \n

Returns what matched the subexpression numbered n. Negative indices are not alowed.

    
por 07.08.2018 / 04:48
0
  • Ctrl + H
  • Encontre o que: ^(?:.*?\(((?:19|20)\d{2})\).*|.*\R)$
  • Substituir por: $1
  • check Embrulhe
  • verificar expressão regular
  • NÃO VERIFIQUE . matches newline
  • Substituir todos

Explicação:

^                   : beginning of line
  (?:               : start non capture group
    .*?             : 0 or more any character but newline, not greedy
    \(              : open parenthesis
      (             : start group 1
        (?:19|20)   : non capture group, 19 or 20
        \d{2}       : 2 digits
      )             : end group 1
    \)              : close parenthesis
    .*              : 0 or more any character but newline
   |                : OR
    .*              : 0 or more any character but newline
    \R?             : any kind of linebreak, optional
  )                 : end non capture group
$                   : end of line

Dada uma entrada como:

hack SIGN (2005) g$
5 Cm Per Second - Makoto Shinkai Collection (2007)
Abenobashi (2002) gd
Ai City - La Notte Dei Cloni (1986) dfg
AIKA (1997)
Anna Dai Capelli Rossi (1979) £$"£
123456 1234
(123) 4567

Temos:

2005
2007
2002
1986
1997
1979
    
por 07.08.2018 / 10:46