in reply to Re^3: regexp find last word
in thread regexp find last word
However, in the present case the last "fox" is the same as the last "fox" before "forest".Well, yes. But if you think it's worthwhile to ignore the question of the OP, and solely focus on the example given, why not give as answer:
That surely works for the example given. It doesn't scale to fit the OP's requirements, but your solution doesn't either.$_ = "fox comes and the fox goes into forest";
Without really exact requirements it's unclear.Then at least state what's unclear, and which things you have implied in your answer. While I agree that the OP doesn't state there could be more than one forest in the sentence, he does write: put the word "the" before the nearest (or last fox) relative to forest. To me, that doesn't imply at all he wants to change the last fox. His problem mentions foxes and a forest - and their relationship.
guessed that the real question posed by the original poster had to do with finding the last "fox", and that the fact that he described it as the last "fox" "relative to forest" was coincidental.If you try to outsmart the user, please, please do say so. Your guess could very well be right, but second guessing the person asking, without stating so is IMO a very bad thing to do. Just imagine your guess was wrong (and that the OP does want to find the last fox before the forest - just as he says), and noone pointed this (like I did). The OP happily takes your answer, only to find out later than your answer doesn't work. He then concludes help received on Perlmonks isn't useful, and never returns to this site. I agree, many people asking questions here ask the wrong question (and for many, had they asked the right question, they had known the answer) - but if you suspect this, and want to answer what you think his/her real question is, say so. It makes answers much more useful (and you'll attract less downvotes for "giving the wrong answer").
It is often quite useful to see some errors and realize just what went wrong in addition to some really slick solution.Too bad that someone asking the question often can't know the difference between right and wrong answers, and than wrong answers not always get corrected, but often also get upvoted (from being the first to answer, or to appear to have given a correct answer).
|
|---|