Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.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
Php Can';我想不出这个正则表达式的解决方案_Php_Regex - Fatal编程技术网

Php Can';我想不出这个正则表达式的解决方案

Php Can';我想不出这个正则表达式的解决方案,php,regex,Php,Regex,我有以下字符串列表: $list = array( 'c1' => '{sometext...} 1tb hdd 1tb hdd {sometext...}' 'c2' => '{sometext...} 1tb hdd 1tb {sometext...}', 'c3' => '{sometext...} hdd 1tb hdd 1tb {sometext...}', 'c4' => '{sometext...} hdd 1tb hdd 1tb hdd {some

我有以下字符串列表:

$list = array(
 'c1' => '{sometext...} 1tb hdd 1tb hdd {sometext...}'
 'c2' => '{sometext...} 1tb hdd 1tb {sometext...}',
 'c3' => '{sometext...} hdd 1tb hdd 1tb {sometext...}',
 'c4' => '{sometext...} hdd 1tb hdd 1tb hdd {sometext...}'
);
下面的正则表达式应该在所有字符串上运行,如果找到匹配项,则返回
true
,否则返回
false

/(

到目前为止,我的结果集如下所示:

'c1' => false,
'c2' => true,
'c3' => false,
'c4' => false
但是,为了得到正确的结果,应该将
c4
标记为
true
。如何更改正则表达式以获得所需的结果

用例:这样做的用例是,正确识别产品标题命名中的模糊属性。在案例1和案例3中,很容易确定哪个容量属于哪个存储设备,但在其他两种情况下,它不可编程确定,因为存在一个没有容量值的
hdd

注意:计算字符串中的
hdd
实例的数量不是一个好的解决方案,因为在字符串的
{sometext…}
部分,文本的其他实例可能会显示为不同类型的噪声。

您可以使用

(?<=(hdd\s)|)\dtb hdd \dtb(?(1)(?=\shdd)|(?!\shdd))
(?:hdd\s+\dtb hdd \dtb(?!\s+hdd)|(?<!hdd\s)\dtb hdd \dtb\s+hdd)(*SKIP)(*F)|\dtb hdd \dtb

只有c4或(c4和c2)?可能
preg_grep(“~”?我首先想到类似的东西(不确定,如果在正确的轨道上)。