English 中文(简体)
引文
原标题:extract double quoted items in a phrase

我想从一个投入短语中引出所有两句,并保留不匹配的内容作为言词。

请允许我说,“销售人员”信息技术,希望产出:

sales people

  IT

“SO”营销“管理”

产出如下:

SO
sales manager
marketing
management

如果投入=“SO”“销售管理”保险

产出如下:

SO
sales manager
marketing
management
insurance

I have found the regex :but i don t know how to extract:

string InputText="SO "sales manager" marketing "management"" ;
string pattern0 = "^"(.*?)"$";
string pattern = "^(.*?)"(.*?)"(.*?)$";
Regex regex = new Regex(pattern);
string[] temOperands;
bool isMatch = regex.IsMatch(InputText);
if (isMatch)
{
    //here goes the extraction
}
最佳回答

我认为,你们需要一些东西,例如<代码>(?<word>[^”]+>、?<word>w+)。 这与案文的双重引用和单一字对应:

var str = @"SO ""sales manager"" marketing hello ""management""";
var regex = new Regex(@"""(?<word>[^""]+)""|(?<word>w+)");
var words = regex.Matches(str)
    .Cast<Match>()
    .Select(m => m.Groups["word"].Value)
    .ToArray();

为了证明这一点,将:

SO
sales manager
marketing
hello
management
问题回答

“销售经理”和“营销”两字仅用两字。 下面的法典可以在双重引用中提取插图。

        ArrayList arr = new ArrayList();

        int x1 ;
        int nextPos=0;
        x1 = InputText.IndexOf( " , 0) +1 ;
        while (x1 != -1)
        {
            if (x1 >= 0)
            { 
                nextPos = InputText.IndexOf( " ,x1);
                arr.Add(InputText.Substring(x1, nextPos - x1));
            }
            nextPos++;
            x1 = InputText.IndexOf( " , nextPos) + 1;
        }

页: 1

string InputText="SO "sales manager" marketing "management"" ;
InputText=InputText.Replace(""","
");

在产出中,你会想到什么。

也可以使用分职能

string s="SO "sales manager" marketing "management"";
string[] ExtractedString= Regex.Split(s, """);




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签