regex - Matching across multiple lines regular expression -


i have several lists in single text file below. starts 0 , ends word unique @ start of newline. rid of of apart line unique on it. looked through stackoverflow , tried following returns whole text file (there other strings in file haven't put in example). problem how account newlines in regex selection

^0(.|\n)* 

input:

0       145 1       139 2       175 3       171 4       259 5       262 6       293 7       401 8       430 9       417 10      614 11      833 12      1423 13      3062 14      10510 15      57587 16      5057575 17      10071 18      375 19      152 20      70 21      55 22      46 23      31 24      25 25      22 26      25 27      14 28      16 29      16 30      8 31      10 32      8 33      21 34      8 35      51 36      65 37      605 38      32 39      2 40      1 41      2 44      1 48      2 51      1 52      1 57      1 63      2 68      1 82      1 94      1 95      1 101     3 102     7 103     1 110     1 111     1 119     1 123     1 129     2 130     3 131     2 132     1 135     1 136     2 137     7 138     4 unique: 252851 

expected output:

unique: 252851 

you need use like

^0[\s\s]*?[\n\r]unique: 

and replace unique:.

  • ^ - start of line
  • 0 - literal 0
  • [\s\s]*? - 0 or more characters incl. newline few possible
  • [\n\r] - linebreak symbol
  • unique: - whole word unique:

another possible regex is:

^0[^\r]*(?:\r(?!unique:)[^\r]*)* 

where \r line endings in current file. replace empty string.

note use (?m)^0.*?[\r\n]unique: regex (to replace unique:) (?m) option:

m: multi-line (dot(.) match newline)


Comments