English 中文(简体)
附录一 议题
原标题:Regex enclosed with () Issue

I m 定期发言

(\w+[ ]*|-\w+[ ]*)(!=|<=|>=|=|<|>| not in | in | not like | like )(.*)

这三节按 com子顺序排列。

当我试图与像这样的东西相匹配时。

product(getProduct_abc) in (Xyz)

它不配对。

但是,当我试图匹配的时候。

100=product(getProduct_abc) in (Xyz)

它完全吻合。

reg?

问题回答

任何东西都不会错,而且经常表达。 这只是不符合具体的指示。

你们需要找到一个很好的参考资料,介绍定期表达和学习基本内容。 http://www.ual-expressions.info/“rel=“nofollow”>。 这或许或不可能很好地提及你作为开端人。 (我正在利用他的雷克迪工具测试你的定期表达。)

这里的表述大致如下:

  • There are three capturing groups, each surrounded by their own pair of parentheses. (Note that parentheses, along with many other characters, have a special meaning in regular expressions, so to match a parenthesis of either direction you need to escape it. The given regular expression does not do this.)
  • In the first capturing group there are two possible choices for a match. They are:
    • One or more "word" characters followed by zero or more spaces, or
    • A dash, followed by one or more "word" characters followed by zero or more spaces
  • In the second capturing group, there are 10 possible matches: the listed operator symbols (without surrounding spaces), or the listed textual operators (with surrounding spaces)
  • In the third capturing group, zero or more of any character at all will match.

(Xyz)的铺设产品(植被-abc)不匹配,因为在<条码>中的操作者,其特性不止是“密码”。 母体不被视为“密码”性质,因此造成相应的失败。

第2条(Xyz)中的100=产品(目标-abc)对应,因为它使用同等产品(=)作为第二组的配对操作者,100是所有“词”特性的体,在“任何特性”部分之后,所有东西都与“任何特性”部分相匹配,因此相匹配。 请注意,视如何处理警戒线,某些语言甚至可能达不到这种距离,如果它处于护法的末尾。

如果第一部指示为,则需要与您的商业用户核对。 也许他们也是以定期表达方式开始的,并给你一个没有工作的人。

这是我看到的:

 100=product(getProduct_abc) in (Xyz)   
Group1 match =  100   
Group2 match =  =   
Group3 match =  product(getProduct_abc) in (Xyz)   

 product(getProduct_abc) in (Xyz)   
        ^  
    Fails here on Group1 match because parenthesis are not included in this group  

You can fix the situation by forcing the last occurance of group 1,2,3 match in the string.
Fixing/Rewriting the equavalent Group1 match and separating the groups, they can be re-combined to force the last match possible.

rxP1 =  (?:-?[w()]+ *) ;
rxP2 =  (?:!=|<=|>=|=|<|>| not in | in | not like | like ) ;
rxP3 =  (?:.*?) ;

rxAll = /(?:$rxP1$rxP2$rxP3)*($rxP1)($rxP2)($rxP3)$/;

In Perl:

use strict;
use warnings;

my @samples = (
  product(getProduct_abc) in (Xyz1) ,
  100=product(getProduct_abc) in (Xyz2) ,
  100 like = != not like >product(getProduct_abc) in (Xyz3) ,
);

my $rxP1 =  (?:-?[w()]+ *) ;
my $rxP2 =  (?:!=|<=|>=|=|<|>| not in | in | not like | like ) ;
my $rxP3 =  (?:.*?) ;

for (@samples)
{
    if ( /(?:$rxP1$rxP2$rxP3)*($rxP1)($rxP2)($rxP3)$/ ) {
        print "
1 =  $1 
";
        print "2 =  $2 
";
        print "3 =  $3 
";
    }
}

产出:

1 =  product(getProduct_abc) 
2 =   in  
3 =  (Xyz1) 

1 =  product(getProduct_abc) 
2 =   in  
3 =  (Xyz2) 

1 =  product(getProduct_abc) 
2 =   in  
3 =  (Xyz3) 




相关问题
Uncommon regular expressions [closed]

Recently I discovered two amazing regular expression features: ?: and ?!. I was curious of other neat regex features. So maybe you would like to share some tricky regular expressions.

regex to trap img tag, both versions

I need to remove image tags from text, so both versions of the tag: <img src="" ... ></img> <img src="" ... />

C++, Boost regex, replace value function of matched value?

Specifically, I have an array of strings called val, and want to replace all instances of "%{n}%" in the input with val[n]. More generally, I want the replace value to be a function of the match ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

Is it possible to negate a regular expression search?

I m building a lexical analysis engine in c#. For the most part it is done and works quite well. One of the features of my lexer is that it allows any user to input their own regular expressions. This ...

regex for four-digit numbers (or "default")

I need a regex for four-digit numbers separated by comma ("default" can also be a value). Examples: 6755 3452,8767,9865,8766,3454 7678,9876 1234,9867,6876,9865 default Note: "default" ...