Hello ,
I have text and I need to find in it a string start with “start” and end with “end”. only the first occurrence.
if the string is :
"just test ... bla ...bla start some txt .... end more text "
"just test ... bla ...bla start some txt .... end more text ".match(/start(.*)end/)
i am getting the correct answer ,array with 2 items:
array[0]="start some txt .... end"
array[1]=" some txt .... "
this is perfect.
when the text contains more the one “end”:
"just test ... bla ...bla start some txt .... end more text xxxx end blue fff ...end"
I cant get the right string whats happening is that the .match(/start(.*)end/) return all the string from the first “start” to last “end” instead of to the first “end” :
return : "start some txt .... end more text xxxx end blue fff ...end"
what I need is only the first occurrence :
"start some txt .... end"
Thanks for the help.
the
?makes it “non-greedy” meaning it’ll match as little as possible