1

i have this string pattern:

Name: bondy
address: kuta, bali
age: 20

i want to get the name value of Name i did regex like this:

/(?<=Name:)(.*)(?=[\n\r])

but somehow it reads until the last newline?

demo: https://regex101.com/r/4U6iU1/1

bondythegreat
  • 1,379
  • 11
  • 18

1 Answers1

4

(.*) is greedy and will try to match everything. Add a ? right after the asterisk to have it be less greedy.

(.*?) tested and worked.

cchoe1
  • 325
  • 2
  • 15