I want to group the first to 15th lines and subsequent lines in a regular expressions

Asked 2 years ago, Updated 2 years ago, 105 views

Line 1
second line
line three
line four
line five
line six
line seven
line eight
line nine
line 10
line 11
line 12
line 13
line 14
line 15
line 16
line 17


in response to the sentence
1st to 15th lines first
I want to group later on line 16 of latter

/(?<first>\A(.*\n){15})(?<latter>.*\z)/
The .*\z does not match to the end of the string, perhaps because of the first match.
rubular: http://rubular.com/r/AQbZAuF7Xs

Please let me know if there are any regular expressions that I can solve.
The environment is ruby:2.5.1
Thank you for your cooperation.

ruby regular-expression

2022-09-30 21:33

1 Answers

. does not include line breaks, and .*\n should also be written on the assumption that it does not include line breaks.

/(?<first>\A(.*\n){15})(?<latter>(.*\n)*\z)/

How about that?


2022-09-30 21:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.