English 中文(简体)
RegEx在扼杀
原标题:RegEx find string in string
  • 时间:2012-01-12 10:31:58
  •  标签:
  • c#
  • .net
  • regex

请允许我利用“试采”来在扼杀中加以扼杀?

I d like to get just the table names from a series of INSERT statements

INSERT INTO tableA VALUES (col1, col2, col3);
INSERT INTO tableB VALUES (col1, col2, col3);
INSERT INTO tableC VALUES (col1, col2, col3);

采用法规 我愿从档案中接过(一米阅读的单线):

tableA
tableB
tableC

I ve Trial with this expression (INTO )([a-z_])* which given me INTO table 我可以用一种子典或替代物给我其他东西,但我猜测这可以在Ref。

最佳回答

Use:

(?i)(?<=intos+)S+

var tables = Regex.Matches(s, @"(?i)(?<=intos+)S+")
    .Cast<Match>().Select(m => m.Value);
问题回答

由于你正在使用C#,我将具体说明我如何从开始到完成:

        //create regex - the (.*?) is a capture group
        var regex = new Regex("INSERT INTO (.*?) VALUES");

        //mimic text lines read from a file
        var sqlStrings = new string[] {"INSERT INTO tableA VALUES (col1, col2, col3)", "INSERT INTO tableB VALUES (col1, col2, col3)", "INSERT INTO tableC VALUES (col1, col2, col3)"};
        foreach (var line in sqlStrings)
        {
            //get the first match with the regex we created
            var match = regex.Match(line);

            //print out the first capture group
            Console.WriteLine(match.Groups[1].ToString());
        }

This will write out the following:

tableA
tableB
tableC

不知道你的确切投入形式(新路线或新格式),也确切地说,你想如何产出,但我希望这样做。

And yes, this can be done a lot more concise, but for clarity s sake I split it up over multiple lines and methods.

用文字编辑取代:

Find: ^INSERT INTO (.*) VALUES.*
Replace: 1

确保对<代码>Regular expression选项进行检查。

我的“诺塔”第2版的屏幕是这样,我相信我,我的工作就是这样。

“entergraph

你们能够从使用寄生虫的对应扼杀中找到一个子:

^ *INSERTs+INTOs+(w+)

从对比结果来看,根据您的语文,您可先使用<1><>>>/代码>或<代码>1查询。

<代码>*和s+均需忽略非白色空间。

in php

$regex = "/INSERT INTO (.*) VALUES/";

页: 1

String regex = "INSERT INTO (.*?) VALUES";

第一个捕获组将掌握你想要的东西。





相关问题
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. ...

热门标签