Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.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
Java 查找Strict并丢失RegExp模式_Java_Regex_String_String Parsing - Fatal编程技术网

Java 查找Strict并丢失RegExp模式

Java 查找Strict并丢失RegExp模式,java,regex,string,string-parsing,Java,Regex,String,String Parsing,我有 这对于从两组字符串中提取“命令”非常有效 ^\s*(\w+(\,\w+)*\s*(:|,|\()(\(|\[)?\s*) 下面是我的问题中更清晰的链接。 您能为strict和lose模式分别编写两个RegExp吗? 因此,使用一个RegExp,我只得到严格的模式命令,而使用另一个,我只得到丢失模式命令 每当我尝试某件事时,我都会超越对方的模式。我无法为每个模式获得一个有效的正则表达式。首先,您可以使用字符类而不是组和交替()来缩短正则表达式: 下面是严格的模式(): 下面是松散的模

我有

这对于从两组字符串中提取“命令”非常有效

^\s*(\w+(\,\w+)*\s*(:|,|\()(\(|\[)?\s*)
下面是我的问题中更清晰的链接。

您能为strict和lose模式分别编写两个RegExp吗?

因此,使用一个RegExp,我只得到严格的模式命令,而使用另一个,我只得到丢失模式命令


每当我尝试某件事时,我都会超越对方的模式。我无法为每个模式获得一个有效的正则表达式。

首先,您可以使用字符类而不是组和交替()来缩短正则表达式:


下面是严格的模式():


下面是松散的模式():

请注意,这些工作适用于您提供的示例数据(如您在Rubular链接中所见),但仅从示例数据和您的正则表达式很难判断这是否涵盖所有可能的情况,如果有问题,您需要更彻底地解释语法

**Strict pattern**
command:some text
command: some text
command,command2: some text

**Loose pattern**
command :some text
command( some text )
command, some txt
^\s*(\w+(,\w+)*\s*[:,(\[]\s*)
^\s*(\w+(,\w+)*:\s*)
^\s*(\w+(,\w+)*(\s+:|\s*[,(\[]\s+)\s*)