简体   繁体   English

正则表达式忽略引号中的字符

[英]Regex Ignore Characters in quotes

Is there a way to ignore text between certain characters?有没有办法忽略某些字符之间的文本? My current regular expression is including text between quotes.我当前的正则表达式包括引号之间的文本。 I need this to be ignored.我需要忽略这一点。

raw_pmc_df\[\'(.*?)]

Current Output:电流输出:

to_max(((100 * **raw_pmc_df['CPF_CPF_STAT_STALL']**) / **raw_pmc_df['CPF_CPF_STAT_BUSY']**).where((**raw_pmc_df['CPF_CPF_STAT_BUSY']** != 0), None))

Desired Output:期望的输出:

to_max(((100 * **raw_pmc_df['** CPF_CPF_STAT_STALL **']**) / **raw_pmc_df['** CPF_CPF_STAT_BUSY **']**).where((**raw_pmc_df['** CPF_CPF_STAT_BUSY **']** != 0), None))

One idea is to use positive lookahead:一种想法是使用积极的前瞻:

raw_pmc_df(?=\['[^']+'\])

The match will be比赛将于

raw_pmc_df

You can add the square brackets afterwards.之后您可以添加方括号。

There is no way to have split matches in common regex engines.没有办法在普通的正则表达式引擎中进行拆分匹配。 In fact there is no need to: you design a regex with multiple capture groups:实际上没有必要:您设计一个具有多个捕获组的正则表达式:

(raw_pmc_df)(\[)(?:'[^']'+)(\])

The desired result is the concatenation of capture groups 1, 2, 3 (the quotes part does not count because of the (: parentheses). This way you do not need a positive lookahead.所需的结果是捕获组 1、2、3 的串联(引号部分不计算在内,因为(:括号)。这样您就不需要积极的前瞻。

In this particular example the regex is contrived as capture groups 2 and 3 contain strings known in advance.在这个特定示例中,正则表达式被设计为捕获组 2 和 3 包含事先已知的字符串。

It seems you want to remove these raw and [' with '] , and keep the contents that are in between.看来您想删除这些raw[' with '] ,并保留其间的内容。

If this is the case, you can use如果是这种情况,您可以使用

raw_pmc_df\[\'(.*?)']

and replace with $1 (or \1 , depending on your programming environment).并替换为$1 (或\1 ,具体取决于您的编程环境)。

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

Details :详情

  • raw_pmc_df\[\' - a raw_pmc_df[' string raw_pmc_df\[\' - raw_pmc_df['字符串
  • (.*?) - Group 1: any zero or more chars other than line break chars as few as possible (.*?) - 第 1 组:除换行符之外的任何零个或多个字符尽可能少
  • '] - a '] string. '] - 一个']字符串。

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

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