Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex将子句的键、运算符和值分组_Regex_Regex Group - Fatal编程技术网

Regex将子句的键、运算符和值分组

Regex将子句的键、运算符和值分组,regex,regex-group,Regex,Regex Group,从如下图所示的子句中获取一组键、运算符和值的最佳正则表达式是什么 到目前为止,我所做的并不准确,只能得到第一组:(^.*?(=|!=)+([^.]*)) 使用 (\w+(?:\.\w+)*)\s*(!=|=)\s*(\w+) 看 解释 -------------------------------------------------------------------------------- ( group and capture to \1

从如下图所示的子句中获取一组键、运算符和值的最佳正则表达式是什么

到目前为止,我所做的并不准确,只能得到第一组:
(^.*?(=|!=)+([^.]*))

使用

(\w+(?:\.\w+)*)\s*(!=|=)\s*(\w+)

解释

--------------------------------------------------------------------------------
  (                        group and capture to \1:
--------------------------------------------------------------------------------
    \w+                      word characters (a-z, A-Z, 0-9, _) (1 or
                             more times (matching the most amount
                             possible))
--------------------------------------------------------------------------------
    (?:                      group, but do not capture (0 or more
                             times (matching the most amount
                             possible)):
--------------------------------------------------------------------------------
      \.                       '.'
--------------------------------------------------------------------------------
      \w+                      word characters (a-z, A-Z, 0-9, _) (1
                               or more times (matching the most
                               amount possible))
--------------------------------------------------------------------------------
    )*                       end of grouping
--------------------------------------------------------------------------------
  )                        end of \1
--------------------------------------------------------------------------------
  \s*                      whitespace (\n, \r, \t, \f, and " ") (0 or
                           more times (matching the most amount
                           possible))
--------------------------------------------------------------------------------
  (                        group and capture to \2:
--------------------------------------------------------------------------------
    !=                       '!='
--------------------------------------------------------------------------------
   |                        OR
--------------------------------------------------------------------------------
    =                        '='
--------------------------------------------------------------------------------
  )                        end of \2
--------------------------------------------------------------------------------
  \s*                      whitespace (\n, \r, \t, \f, and " ") (0 or
                           more times (matching the most amount
                           possible))
--------------------------------------------------------------------------------
  (                        group and capture to \3:
--------------------------------------------------------------------------------
    \w+                      word characters (a-z, A-Z, 0-9, _) (1 or
                             more times (matching the most amount
                             possible))
--------------------------------------------------------------------------------
  )                        end of \3

显然你不知道从哪里开始你的正则表达式。有关正则表达式的详细信息,请查看和[Learning Regular Expressions}()。不太清楚正则表达式应该遵循哪些规则。请尝试
(?:^ |\b(和|或)\s+(\w[\w.]*)\s+(!?=)\s+(\w+)
。请参阅。