Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.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 Regex从字符串中获取特定值_Java_Regex - Fatal编程技术网

Java Regex从字符串中获取特定值

Java Regex从字符串中获取特定值,java,regex,Java,Regex,我试图从带有正则表达式的段落中获取值。我试过使用正则表达式: String regex = "Are you a seller/buyer, a manufacturer, or both for the products you want to list? ANSWER(S): s*([^,]+)" 本段将始终在此子字符串中显示您是要列出的产品的卖家/买家、制造商还是两者?答案:。我希望得到以下值:在给定段落的这个问题中 :后面的字符串可以是=两者之一、卖方、买方或制造商 有人能告诉我我做

我试图从带有正则表达式的段落中获取值。我试过使用正则表达式:

String regex =  "Are you a seller/buyer, a manufacturer, or both for the products you want to list?
ANSWER(S): s*([^,]+)"
本段将始终在此子字符串中显示您是要列出的产品的卖家/买家、制造商还是两者?答案:。我希望得到以下值:在给定段落的这个问题中

:后面的字符串可以是=两者之一、卖方、买方或制造商

有人能告诉我我做错了什么吗


:出现在给定段落的许多地方,字符串中的您是要列出的产品的卖家/买家、制造商还是两者都是?答案将是固定的

因此,如果您只想同时匹配卖方、买方或制造商,可以使用以下正则表达式:

/Are you a seller\/buyer, a manufacturer, or both for the products you want to list\? ANSWER\(S\): (Both|Seller|Buyer|Manufacturer)/
下面是一个示例用法:

const re=/您是要列出的产品的卖家\买家、制造商还是两者兼而有之?答案\ S \:双方|卖方|买方|制造商/; let test=lorem ipsum dolor sit amet您是要列出的产品的卖家/买家、制造商还是两者兼而有之?答案:两种颜色都是同色或同色;
console.loganser是:+re.exectest[1];你能给我们一个冒号后面的字符串是什么样子的例子吗?为什么要使用正则表达式?你知道结果总是在你的段落之后,为什么不使用substring呢?比如:result=regex.substringregex.indexOf:,regex。length@GabLeg因为“:”出现在给定段落的许多地方。s*的目的是什么?您的意思是\\s*?@user3407267,但这是该段中第一次使用冒号吗?