gpt4 book ai didi

.net - 如何使用正则表达式进行多行搜索?

转载 作者:行者123 更新时间:2023-12-01 05:37:21 25 4
gpt4 key购买 nike

我是正则表达式的新手。

我想进行多行搜索。这是我想做的事的例子:

假设我有以下文本:

*Project #1:CVC – Customer Value Creation (Sep 2007 – till now)Time Warner Cable is the world's leading media and entertainment company, Time Warner Cable (TWC) makes coaxial quiver.Client   : Time Warner Cable, US.ETL Tool  : Informatica 7.1.4Database  : Oracle 9i.Role   : ETL Developer/Team Lead.O/S   : UNIX.Responsibilities:Created Test Plan and Test Case Book.Peer reviewed team members Mappings.Documented Mappings.Leading the Development Team.Sending Reports to onsite.Bug fixing for Defects, Data and Performance related.                                                                                                     Project #2:MYER – Sales Analysis system (Nov 2005 – till now)            Coles Myer is one of Australia's largest retailers with more than 2,000 stores throughout Australia,Client   : Coles Myer Retail, Australia.ETL Tool  : Informatica 7.1.3Database  : Oracle 8i.Role   : ETL Developer.O/S   : UNIX.Responsibilities:Extraction, Transformation and Loading of the data using Informatica.Understanding the entire source system.                                                                                     Created and Run Sessions and Workflows.Created Sort files using Syncsort Application.*

I want to write RegEx which should first try to match word "Project" which can be either in small or upper case.

If "project" matches, then RegEx should try to match either client, role, environment.If RegEx. matches ANY ONE of these, then match is complete. (Words client, role, enviornment can be in any case also they may or may not be on the same line as that of word "project")

I have written one regular expression for above task which is like this :

^((P|p)roject.*\s*.*((((E|e)nviornment)|((P|p)latform)|((R|r)ole(s)?)|((R|r)esponsibilit(y|ies))|((C|c)lient)|((C|c)ustomer)|((P|p)eriod)))

这个正则表达式。匹配项目 #1 但不匹配项目 #2。

谁能告诉我这个 RegEx 有什么问题,或者如何为这种文本编写 RegEx?

最佳答案

试试这个:

Regex project = new Regex(
@"^(Project [\s\S]*?" +
@"(Environment|Platform|Roles?|Responsibilit(y|ies)|Client|Customer|Period))",
RegexOptions.ECMAScript | RegexOptions.IgnoreCase | RegexOptions.Multiline);

关于.net - 如何使用正则表达式进行多行搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1606379/

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