|Thank you ijack and FishMonger. I bought the book Perl Programming by Tom Christiansen (and others.) I am feeling rather stupid, but I am afraid that I am stuck on some of these regular expressions and I am finding it difficult to advance given my lack of understanding here. I am hoping you can provide me with some insight. |
I thought that I was following along fairly well until I hit these couple of snags. From the book:
...suppose you’re using the substitution command (s///) on the default string (variable $_, that is), and you want to remove a string of x’s from the middle of the string. If you say:
$_ = “fred xxxxxx barney”;
it will have absolutely no effect. That is because the x* (meaning zero or more x characters) will be able to match “nothing” at the beginning of the string since the null string happens to be zero characters wide and there’s a null string just sitting there plain as day before the “f” of “fred”
My question: if “plain as day?” means “clear as mud”, then I would agree. Is this saying that you need something like “ fred …” or “wilmafred…” in order for x* to apply to this situation? Why does it matter what is in front of fred when all x’s follow fred? Am I misunderstanding the meaning of “in front of”?
And another area of confusion the author writes:
Often someone will have a string like:
and will try to match “larry:” with /.+:/. However the + quantifier is greedy and will match everything up to and including “home/larry:”…Sometimes you can avoid this by using a negated character class; that is, by saying /[^:]+1/, which says to match one or more noncolon character (as many as possible), up to the first colon.
My question: how does /[^:]+1/ match larry: I feel like there is something left out here or maybe that was supposed to be obvious. It feels like it is looking for the colon and not larry