Page 1 of 1
replace last occurance of string in multi line data
Posted: Thu Nov 01, 2012 9:49 am
by shalini
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
Posted: Thu Nov 01, 2012 11:45 am
by Guest
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.
Re: replace last occurance of string in multi line data
Posted: Thu Nov 01, 2012 9:27 pm
by Fool4UAnyway
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".