English 中文(简体)
如果不在一套报价内,就会出现对等(案文跨越多个线)
原标题:Match regex pattern when not inside a set of quotes (text spans multiple lines)
  • 时间:2012-04-05 16:32:54
  •  标签:
  • c#
  • .net
  • regex

这是我先前的问题的继续。 舱面发动机的回报没有匹配,但我预计有8

我的问候是完美地处理所有问题,我的俘虏团体工作出色,但我发现了一个我不知道如何处理的edge案件。

在此,我遇到麻烦的一个试验案例是

INSERT INTO [Example] ( [CaseNumber] , [TestText] )
VALUES
(1 ,  Single Line Case ),
(2 ,  Multi
Line Case );
(3 ,  Two Lines with odd end   );
Case );
(4 ,   ),
(5 ,  Case 3 is the Empty Text Case );

我的格局 我正在使用以下密码:Singleline,Multiline,ExplicitCaptureIgnorePattern Whitespace

^(
((( (?<s>.*?) (?! )) |
 (?<n>-?[d.]+)
 )(s,s)?
)+
#(?<!  )   #Commented Case 3 works, un-commented case 2 works
)[;,]
?$

我既可以处理案件3,也可以处理案件4,但我对这两种情况都感到不安。

如果我能够检查一下是否在捕获组中的<条码>中添加了多少条码>。 然后,我可以检查一下,看看我们是否处于实际的线端,或者在案文栏中,有一条线,目的只是要赶上模式。 但是,我无法说明如何修改

我是否想用一个单一的格列克来做些什么,或者我是否被迫做员额处理(使用所评论的案件),这是否是两张通行证?


在这里,该法典将载于LINQPad。

string text = 
@"INSERT INTO [Example] ( [CaseNumber] , [TestText] )
VALUES
(1 ,  Single Line Case ),
(2 ,  Multi
Line Case );
(3 ,  Two Lines with odd end   );
Case );
(4 ,   ),
(5 ,  Case 3 is the Empty Text Case );
";

const string recordRegex =
@"^(
((( (?<s>.*?) (?! )) |
 (?<n>-?[d.]+)
 )(s,s)?
)+
#(?<!  )   #Commented Case 3 works, un-commented case 2 works
)[;,]
?$";

var records = Regex.Matches(text, recordRegex, RegexOptions.Singleline | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace | RegexOptions.ExplicitCapture);
records.Dump();
最佳回答

这样的表述与这样的引文一致:

(?: [^ ]* )+

如果你想要匹配<代码>foo 在这种引言中,如果是not,你可使用下列内容:

foo(?=[^ ]*(?: [^ ]* [^ ]*)+z)

每一行与未经引述的案文和被俘者人数相符

与此类似:

(?xm)^
(

(?:
    (?:
        (?<quote> (?: [^ ]* )+ )
    |   (?<num>   -?d+(?:.d+)? )
    |   (?<x>     X [0-9a-f]*  )
    )
    (?:s*,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. ...

热门标签