replace last occurance of string in multi line data
replace last occurance of string in multi line data
I have multiline data, in that I want to replace string at last occurrence in PHP. can any one provide suggestion for this
Re: replace last occurance of string in multi line data
I have data as below
"foo
foo
foo
foo
foo
bar
foo
test data
test data"
I want the regular expression or the way how to replace data after last "foo" variable.
Any quick response is helpful.
Thanks.
"foo
foo
foo
foo
foo
bar
foo
test data
test data"
I want the regular expression or the way how to replace data after last "foo" variable.
Any quick response is helpful.
Thanks.
Re: replace last occurance of string in multi line data
Basically, you want to search for:
- any particular string and anything following it, any number of time
- the same particular string
- some text after that
And replace that by
- "any particular string and anything following it, any number of time"
- "the same particular string"
- new text after all above
You have to capture the first two parts of the regular expression and then replace the "text after" with the "new text after".
- any particular string and anything following it, any number of time
- the same particular string
- some text after that
And replace that by
- "any particular string and anything following it, any number of time"
- "the same particular string"
- new text after all above
You have to capture the first two parts of the regular expression and then replace the "text after" with the "new text after".