gpt4 book ai didi

regex - 这个正则表达式怎么写?

转载 作者:行者123 更新时间:2023-12-04 18:23:02 25 4
gpt4 key购买 nike

这是一个包含公式和生物代码的巨大文件的样本。部分线路 开头以下字符:

Sheep"-head`ed,   // followed by some normal words 
Mon`o*car*bon"ic, // followed by some normal words
mon`o*car"di*an, // followed by some normal words
Pol`y*chro"mate, // followed by some normal words
sheep"cot`, // followed by some normal words
baad, // followed by some normal words

我是正则表达式的新手。现在我正在尝试使用 TPerlRegEx ( a wrapper of PCRE library)。我需要提取:
Sheep"-head`ed,   
Mon`o*car*bon"ic,
mon`o*car"di*an,
Pol`y*chro"mate,
sheep"cot`,
baad,

你能帮我写一个正则表达式吗?

非常感谢。

编辑:

感谢大家的帮助。如果它们之间有法线:
Sheep"-head`ed,   // followed by some normal words 
Mon`o*car*bon"ic, // followed by some normal words
New test, //I do not want two or more than two words that end with comma.
mon`o*car"di*an, // followed by some normal words
Pol`y*chro"mate, // followed by some normal words
sheep"cot`, // followed by some normal words
baad, // I want this one word that ends with comma

我还想要:
Sheep"-head`ed,   
Mon`o*car*bon"ic,
mon`o*car"di*an,
Pol`y*chro"mate,
sheep"cot`,
baad, // I want this ONE word that ends with comma.

再次感谢你。

最佳答案

原始正则表达式是 ^[^,]+, perl 中的正则表达式:/^[^,]+,/

  • ^匹配行首
  • [^ ,]+匹配尽可能多的非逗号、非空格。
  • ,匹配逗号
  • 关于regex - 这个正则表达式怎么写?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10248481/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com