0

I have column of dates in my Notepad++:

2017-06-12
2017-06-13
2017-06-14
2017-06-15
2017-06-16
2017-06-17
2017-06-18
2017-06-19
2017-06-20
2017-06-20
2017-06-21
2017-06-22
2017-06-23
2017-06-24
2017-06-25
2017-06-26
2017-06-27
2017-06-28
2017-06-29
2017-06-30
2017-07-01
2017-07-02
2017-07-03
2017-07-04
2017-07-05
2017-07-06
2017-07-07
2017-07-08
2017-07-09
2017-07-10

I need it to cut in weeks by placing \r\n after each week like :

2017-06-12
2017-06-13
2017-06-14
2017-06-15
2017-06-16
2017-06-17
2017-06-18

2017-06-19
2017-06-20
2017-06-20
2017-06-21
2017-06-22
2017-06-23
2017-06-24
2017-06-25

2017-06-26
2017-06-27
2017-06-28
2017-06-29
2017-06-30
2017-07-01
2017-07-02

2017-07-03
2017-07-04
2017-07-05
2017-07-06
2017-07-07
2017-07-08
2017-07-09

2017-07-10

I do replace by using RegEx. I find 7 days:

\d\d\d\d-\d\d-\d\d\r\n\d\d\d\d-\d\d-\d\d\r\n\d\d\d\d-\d\d-\d\d\r\n\d\d\d\d-\d\d-\d\d\r\n\d\d\d\d-\d\d-\d\d\r\n\d\d\d\d-\d\d-\d\d\r\n\d\d\d\d-\d\d-\d\d\r\n

And now I would like to add \r\n

But how to use selected data for replace with itself plus \r\n ?

vico
  • 13,725
  • 30
  • 108
  • 237

2 Answers2

0

If you are sure that the first date is monday, you could that:

  • Ctrl+H
  • Find what: (?:\d{4}-\d\d-\d\d\R){7}
  • Replace with: $0\r\n
  • Replace all
Toto
  • 83,193
  • 59
  • 77
  • 109
0

In your example input there are some lines doubled. e.g. the 2017-06-20. In your example output this line is also doubled and the week-block consists of eight lines. Seven unique lines and one doubled line for 2017-06-20. I assume that all lines in the input are sorted, thus non unique lines are behind each other. Additionally I assume that the first line marks the first day of a week.

Do a regular expression find/replace like this:

  • Open Replace Dialog
  • Find What: (((.*\R)\3*){7})
  • Replace With: \1\r\n
  • Check regular expression, do not check . matches newline
  • Click Replace or Replace All

Explanation

Lets explain (((.*\R)\3*){7}) from the inside out, starting at the third inner group: in the following x,y are regex-parts and do not mean literal characters.

  • (.*\R) the third group is just one line from start to end
  • (y\3*) we look for a y followed by an optional part that is captured in the third braces group, here it means a y followed by an optional number of repetitions of y, here y is the third group referenced by \3; this deals with the 2017-06-20 case
  • (x{7}) we match seven repetions of x, which means here seven unique rows wich can have repetitions in the block, so 8 line with one line doubled is ok
Lars Fischer
  • 7,817
  • 3
  • 24
  • 31