2

I'm trying to select a word that is on the second line, but first I need to check if there is a word on the first line, regex example:

(?<=isaac)select

this is the text

abcdefgisaachijklmnopqrstuvwxyz
abcdefgselecthijklmno

Just to clarify my idea a little

enter image description here

Why doesn't this regex work when isaac precedes select?

How can I solve this?

user207421
  • 305,947
  • 44
  • 307
  • 483
megaultron
  • 399
  • 2
  • 15

2 Answers2

3

You can change issac so it is in a non-capture group, and allow for anything until select is present.

(?s)(?:isaac.*)(select)

The (?s) modifies the . operator so it allows for new lines as well.

https://regex101.com/r/qPQH25/1

user3783243
  • 5,368
  • 5
  • 22
  • 41
  • Your regex matches `"My name is isaac m. newton, let's see if select is \non the next line"`. Also I don't understand the point of having `isasc.*` in a non-capture group. – Cary Swoveland Oct 05 '21 at 02:33
1

Since the two words are given there is no point to select the word in the second line; it is enough to determine if the first word is in the first line and the second word is in the second line.

The needed regular expression is simple:

.*isaac.*\n.*select

Start your engine!

Cary Swoveland
  • 106,649
  • 6
  • 63
  • 100