-1

How do I extract the string in between but not consuming the characters,

The string:

abc123
def456
ghi789

I was using the regex below and it returns the string in between 123 and 789:

/123(.*?)789/s

What I want to extract is:

123
def456
ghi789
Tatt Ehian
  • 79
  • 1
  • 7

1 Answers1

2

The capturing parens should be placed around what you want to capture, so replace

/123(.*?)789/s

with

/(123.*?789)/s

Now, 123 and 789 will be included in the captured text as requested.

ikegami
  • 367,544
  • 15
  • 269
  • 518