Javascript regex pattern matches multiple lines (AND, OR) for one line

I need to filter a collection of strings based on a rather complex query - in it the "raw" form looks like this:

nano* AND (regulat* OR *toxic* OR ((risk OR hazard) AND (exposure OR release)) )

An example of one of the lines to match:

Workshop on the Second Regulatory Review on Nanomaterials, 30 January 2013, Brussels

So, I need to match AND OR characters and wildcards, so I guess I will need to use a regular expression in JavaScript.

I loop everything correctly, filter and work in general, but I am 100% sure that my regular expression is erroneous, and some results are mistakenly omitted - here it is:

/(nano[a-zA-Z])?(regulat[a-zA-Z]|[a-zA-Z]toxic[a-zA-Z]|((risk|hazard)*(exposure|release)))/i

Any help would be greatly appreciated - I really can't properly abstract my mind to understand this syntax!

UPDATE:

, , , , , ,

UPDATE:

, PHP - twitter API 1.0, . pastebin, ( , , ...):

: http://pastebin.com/MpWSGtHK : http://pastebin.com/pP2AHEvk

+5
2

, IMO:

/^(?=.*\bnano)(?=(?:.*\bregulat|.*toxic|(?=.*(?:\brisk\b|\bhazard\b))(?=.*(?:\bexposure\b|\brelease\b))))/i.test(subject))

True, , , , . JavaScript , :

^                 # Anchor search to start of string
(?=.*\bnano)      # Assert that the string contains a word that starts with nano
(?=               # AND assert that the string contains...
 (?:              #  either
  .*\bregulat     #   a word starting with regulat
 |                #  OR
  .*toxic         #   any word containing toxic
 |                #  OR
  (?=             #   assert that the string contains
   .*             #    any string
   (?:            #    followed by
    \brisk\b      #    the word risk
   |              #    OR
    \bhazard\b    #    the word hazard
   )              #    (end of inner OR alternation)
  )               #   (end of first AND condition)
  (?=             #   AND assert that the string contains
   .*             #    any string
   (?:            #    followed by
    \bexposure\b  #    the word exposure
   |              #    OR
    \brelease\b   #    the word release
   )              #    (end of inner OR alternation)
  )               #   (end of second AND condition)
 )                #  (end of outer OR alternation)
)                 # (end of lookahead assertion)

, , .

:

if (/\bnano/i.test(str) &&
    ( 
        /\bregulat|toxic/i.test(str) ||
        ( 
            /\b(?:risk|hazard)\b/i.test(str) &&
            /\b(?:exposure|release)\b/i.test(str)
        )
    )
)    /* all tests pass */
+19

. "nano" "regulat" , . , regexen , :

if (str.indexOf('nano') > -1) {
    if (str.indexOf('regulat') > -1 || str.indexOf('toxic') > -1
        || ((str.indexOf('risk') > - 1 || str.indexOf('hazard') > -1)
        && (str.indexOf('exposure') > -1 || str.indexOf('release') > -1)
    )) {
        /* all tests pass */
    }
}

(, "", "regulat" ), .

+2

All Articles