简体   繁体   English

匹配正则表达式模式中的特定字符串

[英]Matching specific strings in regex pattern

I have multiple records and I want to match specific strings and at the same time unmatched specific strings.我有多个记录,我想匹配特定的字符串,同时不匹配特定的字符串。 I came up with one pattern but it matches all.我想出了一种模式,但它匹配所有模式。 Anyone can revise the pattern please?任何人都可以修改模式吗?

Pattern: /PF\s*(?:XAP|FNI)?\s*O\/\s*(?:RG|VO|HS).*\s*\+?(?!HSAC|VOG)/gm

Here are the records-

Here are the records should be matched:
PFO/RGETK
PFO/RGETK+/RGETK
PFO/VOG+/RGETK
PFO/VOG+/VOG
PFO/RGETK+/VOG
PFXAPO/RGETK
PFXAPO/RGETK+/RGETK
PFXAPO/VOG+/RGETK
PFXAPO/VOG+/VOG
PFXAPO/RGETK+/VOG
PFFNIO/RGETK
PFFNIO/RGETK+/RGETK
PFFNIO/VOG+/RGETK
PFFNIO/VOG+/VOG
PFFNIO/RGETK+/VOG
PF O/RGETK+/HSAC
PF O/HSAC+/RGETK
PF O/RG+/RGETK
PF O/RG+/HSAC

Here are the records should NOT be matched:
PFO/VOG
PFO/VOG+/HSAC
PFO/HSAC+/HSAC
PFXAPO/VOG
PFXAPO/VOG+/HSAC
PFXAPO/HSAC+/HSAC
PFFNIO/VOG
PFFNIO/VOG+/HSAC
PFFNIO/HSAC+/HSAC

You can use您可以使用

^PF\s*(?:(?:XAP|FNI)\s*)?O\/(?!\s*(?:VOG\+?(?:\/HSAC)?|HSAC\+?\/HSAC)$)\s*(?:RG|VO|HS)[A-Z]*\+?(?:\/[A-Z]+)?$

See the regex demo .请参阅正则表达式演示

Details :详情

  • ^ - start of string ^ - 字符串的开始
  • PF - PF PF - PF
  • \s* - zero or more whitespaces \s* - 零个或多个空格
  • (?:(?:XAP|FNI)\s*)? - an optional sequence of XAP or FNI and then zero or more whitespaces - 可选的XAPFNI序列,然后是零个或多个空格
  • O\/ - O/ O\/ - O/
  • (??\s*(:?VOG\+?(:?\/HSAC)?|HSAC\+?\/HSAC)$)
  • \s* - zero or more whitespaces \s* - 零个或多个空格
  • (?:RG|VO|HS) - RG , VO or HS (?:RG|VO|HS) - RGVOHS
  • [AZ]* - zero or more uppercase ASCII letters [AZ]* - 零个或多个大写 ASCII 字母
  • \+? - an optional + char - 一个可选的+字符
  • (?:\/[AZ]+)? - an optional sequence of / and one or more ASCII uppercase letters - 可选的/序列和一个或多个 ASCII 大写字母
  • $ - end of string. $ - 字符串结尾。

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

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