How to avoid infinite loops in the .NET RegEx class?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Got a simple task to get a XPath expression and return a prefix that matches the parent of the node that (might be) selected. Example: /aaa/bbb => /aaa /aaa/bbb/ccc => /aaa/bbb /aaa/bbb/ccc[@x='1' and @y="/aaa[name='z']"] => /aaa/bbb Because the patterns inside the square brackets might contain brackets within quotes, I decided to try to achieve this with the use of regular expressions. Here's a code snippet: string input = "/aaa/bbb/ccc[@x='1' and @y=\"/aaa[name='z'] \"]"; // ^-- remove space for no loop string pattern = @"/[a-zA-Z0-9]+(\[(