简体   繁体   English

java正则表达式:以任何顺序匹配多个逗号分隔的字符串

[英]java regex: match multiple comma separated strings in any order

I have an incoming String like "Product Options, Server Applications, CurrentVersion" I have to create a REGEX to match a Value to the above string containing all comma separated strings in any order Case insensitive.我有一个传入的字符串,如“产品选项、服务器应用程序、当前版本”我必须创建一个 REGEX 以将一个值与上面的字符串匹配,其中包含以任何顺序不区分大小写的所有逗号分隔字符串。


  1. eg "Currentversion, Product options, server applications" should match例如“当前版本、产品选项、服务器应用程序”应该匹配

  2. "Productoptions, currentversion, server applications" should NOT match “产品选项、当前版本、服务器应用程序”不应匹配

  3. "server applications, Product options, Currentversion" should match “服务器应用程序、产品选项、当前版本”应该匹配

Here's the answer I came up with:这是我想出的答案:

For regex based solution the following should work-对于基于正则表达式的解决方案,以下应该有效-

String r =^(?=.*Product Options)(?=.*Server Applications)(?=.*CurrentVersion).*$
Pattern p= Pattern.compile(r, Pattern.CASE_INSENSITIVE);
p.matcher(s).matches()

This should match the strings found in any order这应该匹配以任何顺序找到的字符串

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM