Tuesday, 7 June 2016

php - regular expression text merge



Is this possible in reg-ex?




subject='fox';
adjective='quick brown';
verb='jumps';
text='The <> <> <> over the lazy dog.'





reg-ex would return:




'The quick brown fox jumps over the lazy dog.'



Answer



You don't even need regular expressions to do that. I assume PHP has a string.Replace function of some sort, right? So wouldn't you just be doing (in C#, sorry):



text = "The <> <> <> over the lazy dog.";

text = text.Replace("<>", adjective);
text = text.Replace("<>", subject);
text = text.Replace("<>", verb);

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...