Le 07/03/2011 15:13, Stan Hoeppner a écrit :
> 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$/

.dynamic.chello.sk      REJECT blah blah


> /^(\d{1,3}\.){4}dsl\.dyn\.forthnet\.gr$/

.dyn.forthnet.gr        REJECT blah blah

> /^(\d{1,3}-){4}adsl-dyn\.4u\.com\.gh$/
/dyn\.4u.com\.gh$/      REJECT blah

assuming you get real mail from there. otherwise
.4u.com.gh      REJECT blah

> /^[\d\w]{8}\.[\w]{2}-[\d]-[\d\w]{2}\.dynamic\.ziggo\.nl$/

ahem? I fail to see what yoy're trying to match here. \d is a \w, so
[\d\w] is the same as \w. do you mean \W (capital letter)? anyway:

.dynamic.ziggo.nl        REJECT blah blah

> /^(\d{1,3}\.){4}dynamic\.snap\.net\.nz$/
.dynamic.snap.net.nz    REJECT blah

> /^pppoe-dyn(-\d{1,3}){4}\.kosnet\.ru$/
/\Wdyn\W.*\.kosnet\.ru$/        REJECT blah

> 
>> 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?

well, that's what regular expressions are about by default:
/foo/ means contains foo
/^foo/ means starts with foo
/foo$/ means ends with foo

so
/^bart.*homer.*marge$/ means: starts with "bart", ends with "marge" and
somewhere between these contains "homer".


> 
>> 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. :)
> 

Reply via email to