简体   繁体   English

如何在正则表达式中放置多个或多个条件

[英]How to put more than one or condition in regex

Below are the cases to cover using regular expression: 以下是使用正则表达式涵盖的情况:

Case 1: (3) x 4.5 mL Red Top Tubes. 情况1: (3)x 4.5 mL红顶管。

Case 2: (3) 4mL Red Top Tubes. 情况2: (3)4mL红顶管。

Case 3: (3)- 4mL Red Top Tubes. 情况3: (3)-4mL红顶管。

I have created regular expression to cover all these above cases: 我创建了正则表达式来涵盖上述所有情况:

But it is not working for ' Case 3 ' where separator is '-' 但不适用于分隔符为“-”的“ 案例3

(\(([^)]+)\)(?:\s*x\s*|\s*|-)(\d*\.\d+|\d+)\s*ml\s([\w\s]+)[,\;\and\s]*)

Output 产量 在此处输入图片说明

Thanks in advance !! 提前致谢 !!

Your regex doesn't match on - since second alternative \\s* is an all-time match that satisfies engine right there. 您的正则表达式不匹配-因为第二个替代\\s*是一直满足该要求的引擎的匹配项。 Your regex don't need all those alternations either: 您的正则表达式也不需要所有这些更改:

\(([^)]+)\)\s*[x-]?\s*(\d+(?:\.\d+)?)\s*m[lL]\b([\w\s]+)

Live demo 现场演示

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

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