为什么在这个看似有效的正则表达式中进行灾难性的回溯?(why catastrophic backtracking in this seemingly valid regular expression?)
这是我的输入文字:
1. Text text 2. more text.. 3. more text... 4. more text.. 5. more text.. some more text here.. 1. This is another text. 2. This is another text contd 3. More text..
现在,当我使用这样的正则表达式来匹配这个文本时:
1\.(.+?)\n2\.(.+?)\n3\.
这工作正常,并匹配前3行和最后3行,但是,当我在正则表达式中包含其他数字时:
1\.(.+?)\n2\.(.+?)\n3\.(.+?)\n4\.(.+?)\n5.(.+?)
它导致立即灾难性的回溯错误。
我正在使用regex101和标志g和s。
为什么正则表达式引擎不会忽略文件尾部的第二个(部分)匹配?
This is my input text:
1. Text text 2. more text.. 3. more text... 4. more text.. 5. more text.. some more text here.. 1. This is another text. 2. This is another text contd 3. More text..
Now, when I use a regular expression like this to match this text:
1\.(.+?)\n2\.(.+?)\n3\.
This works fine, and matches the first 3 lines and the last 3 lines, however, when I include the other numbers in the regular expression:
1\.(.+?)\n2\.(.+?)\n3\.(.+?)\n4\.(.+?)\n5.(.+?)
It results in an immediate catastrophic backtracking error.
I am using regex101 and flags g and s.
Test case with actual data on regex101.
Why doesn't the regex engine ignore the second (partial) match towards the end of the file?
原文:https://stackoverflow.com/questions/31923063
最满意答案
有一个额外的入口点,可以显示基于命令行参数的不同形式。 (它可以像通过反射找到指定类型并调用入口点一样简单,或者是一个switch语句......)我很确定用于调试的命令行参数最终在“.user”版本的项目文件(因为它们被设计为按用户设置)。 只要确保你不要把.user文件放入svn!
Have an extra entry point which can show different forms based on a command line argument. (It could be as simple as finding the specified type by reflection and calling the entry point. Or a switch statement...) I'm pretty sure that the command line arguments used for debugging end up in the ".user" version of the project file (because they're designed to be per-user settings). Just make sure you don't put the .user files into svn!
相关问答
更多-
vb.net那里下载[2022-12-02]
官方下载地址:http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-basic-express 此为:vb.net express版本,没有时间限制 -
因此,当操作系统启动您的程序时, 当前目录是%windir%\System32 。 您需要调整所有现有路径以明确相对于Application.ExecutablePath或put My.Computer.FileSystem.CurrentDirectory = My.Application.Info.DirectoryPath 在程序的开头(这是ChDir ...的现代版本ChDir ... )。 So when the O/S starts your program the Current Direc ...
-
无法在Visual Studio 2012中设置启动窗体(VB.NET)(Unable to Set Startup Form in Visual Studio 2012 (VB.NET))[2023-05-11]
在form2中的new()函数中添加InitializeComponent() add InitializeComponent() in new() function in form2 -
取消选中Project Properties中的Enable Application Framework 。 Uncheck Enable Application Framework in Project Properties.
-
你可以试试 System.AppDomain.CurrentDomain.BaseDirectory 这对大多数情况都适用。 You could try System.AppDomain.CurrentDomain.BaseDirectory which would work for most cases.
-
您可以使用Environment.GetSpecialFolder函数找到启动文件夹,然后使用File.Copy将文件复制出来。 Public Sub CopyIconFromStartup(iconName as String, target As String) Dim path as String = Environment.GetSpecialFolder(SpecialFolder.Startup) path = IO.Path.Combine(path, iconName) Fil ...
-
不同的开发人员在VB.NET中使用SVN的不同启动形式?(Different startup forms for different developers using SVN in VB.NET?)[2023-04-27]
有一个额外的入口点,可以显示基于命令行参数的不同形式。 (它可以像通过反射找到指定类型并调用入口点一样简单,或者是一个switch语句......)我很确定用于调试的命令行参数最终在“.user”版本的项目文件(因为它们被设计为按用户设置)。 只要确保你不要把.user文件放入svn! Have an extra entry point which can show different forms based on a command line argument. (It could be as simpl ... -
那么,首先,WinForms控件被命名为DataGridView 。 但是要回答这个问题,不,他们建立在两种根本不同的技术上。 Well, first of all, the WinForms control is named DataGridView. But to answer the question, no, they are built on two fundamentally different technologies.
-
别猜这个。 为AppDomain.Current.UnhandledException编写一个事件处理程序,并显示e.ExceptionObject.ToString()的值。 在VB.NET窗体表单应用程序中: Partial Friend Class MyApplication Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.Applicat ...
-
使用vb.net打印(Printing with vb.net)[2022-08-09]
取自http://visualbasic.about.com/od/usingvbnet/a/printvb2005.htm Public Class myPrinter Friend TextToBePrinted As String Public Sub prt(ByVal text As String) TextToBePrinted = text Dim prn As New Printing.PrintDocument Using (prn) ...