Noel Jones put forth on 3/7/2011 7:00 AM:
> On 3/7/2011 4:47 AM, Stan Hoeppner wrote:
>>
>> 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?
> 
> That's good advice when you're actually matching something.

Ok, so if I'm doing what I've heard called a "fully qualified regular
expression", WRT FQrDNS matching, should I use the anchors or not?
postmap -q says these all work (the actuals with action and text that is).

/^(\d{1,3}-){3}\d{1,3}\.dynamic\.chello\.sk$/
/^(\d{1,3}\.){4}dsl\.dyn\.forthnet\.gr$/
/^(\d{1,3}-){4}adsl-dyn\.4u\.com\.gh$/
/^[\d\w]{8}\.[\w]{2}-[\d]-[\d\w]{2}\.dynamic\.ziggo\.nl$/
/^(\d{1,3}\.){4}dynamic\.snap\.net\.nz$/
/^pppoe-dyn(-\d{1,3}){4}\.kosnet\.ru$/

> The special case of .* means, as you know, "anything or nothing". 
> There's never a case where it's necessary to explicitly match a leading
> or trailing "anything or nothing".

What of the case where you want to match something in the middle of the
input string, with extra junk on both ends?

> Consider:
> /^.*foo$/
>   match the string beginning with anything or nothing, ending with foo.
> 
> can always be simplified to:
> /foo$/
>   match the string ending with foo.
> 
> This works the same without the ending $ anchor (contains foo, rather
> than ends with foo), but helps the illustration.

So, in my examples above, given we're matching rDNS patterns, are the
anchors necessary, or helpful?  If not using them means "contains", then
they should still match.  What advantage is there to using the anchors
when matching rDNS patterns?  Any?

> (In the other special case where you're using $1, $2, etc. substitution
> in the result, you might need some form of /^(.*foo)$/ to fill the
> substitution buffer, but that's about substitution, not about matching.)

Thank you for the continuing PCRE education Noel, and Ansgar. :)

-- 
Stan

Reply via email to