vertito wrote:
> so 
>
> cloudy mountainers  
>
> will still be catched by ORing both of 2 expression, that would 
> produce AND expression, is that right?
>   
/[\s']((mountain.*clouds)|(clouds.*mountain))[\s',-]/i  will NOT match
cloudy mountaineers. It will fail because of the [\s',-] at the end
which REQUIRES a space, comma, dash or single quote. It would match
cloudy mountain.

/((mountain.*clouds)|(clouds.*mountain))/i  WILL match cloudy
mountaineers.. There are no restrictions on what characters come before
or after the expression.


> so 2 expressions ORred together will have the same result as single ANDed 
> expression, right?
>   
You can create the equivalent of an AND by ORing together two of the
right expressions, yes.

a AND b can be expressed as:  (a THEN b) OR (b THEN a). 

a.*b will match a followed by b, with any number of any kind of
character in between. It's half of an AND, in that it requires both to
be present, but is order-specific in nature. If you want to match either
order, you'd need to OR together a.*b and b.*a.

Hence:
/(a.*b)|(b.*a)/

The [\s',-] or \b's can be added to the beginning and end to force
various kinds of word boundaries, if you wish to avoid matching
substrings. I personally prefer \b for normal text.

I'd only use something like [\s',-] if I wanted to restrict what kinds
of things are a "word boundary".. ie: If I wanted to exclude period,
colon, and other punctuation other than the ones in the expression. This
kind of thing can be useful in a few cases where the kinds of
punctuation that can be used are restricted, such as URLs or email
addresses, but is not useful in general text processing.


Reply via email to