On 2011-03-07 Stan Hoeppner wrote: > mouss put forth on 3/6/2011 7:03 PM: >> /^.*foo/ >> means "it starts with something followed by foo". and this is the same >> thing as "it contains foo", which is represented by >> /foo/ > > I was taught to always start my expressions with "/^" and end them > with "$/". Why did Steven teach me to do this if it's not necessary?
I wouldn't know what his rationale was, but Noel and mouss are certainly right. "Anchoring" something between wildcard matches is utterly pointless. As mouss explained above, /^.*foo/, /.*foo/ and /foo/ produce the same results. That is, unless your regexp processor implicitly anchors an expression at the beginning of the string, in which case you'd need the leading .*, but still won't need to explicitly anchor it with a ^. Regards Ansgar Wiechers -- "Abstractions save us time working, but they don't save us time learning." --Joel Spolsky