首页 \ 问答 \ 异常处理机制如何在.net中真正起作用?(How exception handling mechanishm really works in .net?)

异常处理机制如何在.net中真正起作用?(How exception handling mechanishm really works in .net?)

我想知道,异常处理机制如何在.net中运行?

只是想知道,内部运行时会发生什么?


I wonder, How exception handling mechanishm actualy works in .net?

Just want to know, what happens in runtime internally?


原文:https://stackoverflow.com/questions/810454
更新时间:2023-04-02 19:04

最满意答案

In [163]: re.split(r'\s*([&|^])\s*', 'name1|name2', maxsplit=1)
Out[163]: ['name1', '|', 'name2']

maxsplit=1会使re.split最多匹配1个匹配项:

In [164]: re.split(r'\s*([&|^])\s*', 'name1|nam^e2', maxsplit=1)
Out[164]: ['name1', '|', 'nam^e2']

您还可以使用非贪婪的搜索:

In [184]: re.search(r'\s*(.*?)\s*([&|^])\s*(.*?)\s*', 'name1 | nam^e2').groups()
Out[184]: ('name1', '|', 'nam^e2')

这样做的好处是还可以在字符串的开头和结尾处跳过空白。

第一组的非贪婪(.*?)允许([&|^])匹配第一次出现的&| ,或^


In [163]: re.split(r'\s*([&|^])\s*', 'name1|name2', maxsplit=1)
Out[163]: ['name1', '|', 'name2']

maxsplit=1 causes re.split to make at most 1 match:

In [164]: re.split(r'\s*([&|^])\s*', 'name1|nam^e2', maxsplit=1)
Out[164]: ['name1', '|', 'nam^e2']

You could also use a non-greedy search:

In [184]: re.search(r'\s*(.*?)\s*([&|^])\s*(.*?)\s*', 'name1 | nam^e2').groups()
Out[184]: ('name1', '|', 'nam^e2')

This has the advantage of also tripping off the whitespace at the beginning and end of the string.

The non-greediness of the first group, (.*?) allows ([&|^]) to match the first occurrence of &, |, or ^.

相关问答

更多
  • \{\#([a-zA-Z]+\()?(en|kr)\.[a-zA-Z0-9_]+[\)]?\} ^^ 你忘了量词。参见演示。 https://regex101.com/r/pG1kU1/12#python \{\#([a-zA-Z]+\()?(en|kr)\.[a-zA-Z0-9_]+[\)]?\} ^^ You forgot a quantifier.See demo. https://regex101.com/r/pG1kU1/12#pytho ...
  • 在这种情况下,它只是用作分隔符。 通常,在PHP中,正则表达式的第一个和最后一个字符是“分隔符”,用于标记匹配部分的开始和结束位置(如果您想要在末尾添加修饰符,如非平凡等) 通常,PHP从一个字符串中的第一个字符开始,这是一个正则表达式,将其作为第二个分隔符的第二个字符匹配。 这在文本中出现正常分隔符时(例如,文本中的出现) - 这意味着您不必做尴尬的事情就很有用。 匹配“ // ”与分隔符设置为“ / ” /\/\// 匹配“ // ”与分隔符“ # ” #//# In this case, it's j ...
  • 是的: !~工作很好 - 你可能以为没有,因为它从Regexp的文档页面中缺少 。 不过,它有效: irb(main):001:0> 'x' !~ /x/ => false irb(main):002:0> 'x' !~ /y/ => true Yes: !~ works just fine – you probably thought it wouldn’t because it’s missing from the documentation page of Regexp. Nevertheless, ...
  • 你可以自己使用管道: "string1|string2" 例如: String s = "string1, string2, string3"; System.out.println(s.replaceAll("string1|string2", "blah")); 输出: blah, blah, string3 使用括号的主要原因是限制替代方案的范围: String s = "string1, string2, string3"; System.out.println(s.replaceAll("s ...
  • @ maxymoo的答案对于您发布的示例是正确的,但如果您的语料库中的某些单词包含斜杠(例如,“和/或”)或连字符,则无效。 要捕获带连字符的单词,请用(\w+-\w+|\w+)替换答案中的(\w+-\w+|\w+) 。 斜线更难。 您需要收集完整的标签列表并编写预测。 @maxymoo's answer is correct for the example you posted, but will not work if some words in your corpus contain slashes ...
  • Python正则表达式使用| 操作员进行轮换。 def series2string(myserie) : myserie2 = '|'.join(serie for serie in myserie) myserie2 = '(' + myserie2 + ')' return myserie2 更多信息: https : //docs.python.org/3/library/re.html 个人模式看起来非常混乱,所以我不知道什么是错误,什么是故意的。 我猜你正在几个不同的环境 ...
  • 通过简单的字符串操作,您可以更清楚地了解它。 my_string = '1: foo bar baz' num_string, word_string = my_string.split(':') num = int(num_string) words = word_string.strip().split(' ') print(num) print(words) 输出: # num = 1 # words = ['foo', 'bar', 'baz'] You can probably make i ...
  • In [163]: re.split(r'\s*([&|^])\s*', 'name1|name2', maxsplit=1) Out[163]: ['name1', '|', 'name2'] maxsplit=1会使re.split最多匹配1个匹配项: In [164]: re.split(r'\s*([&|^])\s*', 'name1|nam^e2', maxsplit=1) Out[164]: ['name1', '|', 'nam^e2'] 您还可以使用非贪婪的搜索: In [184]: r ...
  • 您需要第一个捕获的组: a.group(1) b.group(1) ... 没有任何捕获的组规范作为group()参数,它将显示完全匹配,就像你现在得到的那样。 这是一个例子: In [8]: string_one = 'file_record_transcript.pdf' In [9]: re.search(r'^(file.*)\.pdf$', string_one).group() Out[9]: 'file_record_transcript.pdf' In [10]: re.search( ...
  • 这应该做到这一点: /(?:.* and )?(.+)/ 请注意,这与整行匹配,但捕获的匹配将是您想要的部分。 这里有一个工作的例子。 但有几点需要注意: 这假定每行有一个句子。 当它没有单词“和”时,这将匹配整行。 也许这就是你想要的。 这假设该行的第一个单词不是'和'。 这也假设该行的最后一个字不是'和'。 This should do it: /(?:.* and )?(.+)/ Note that this matches the entire line, but the captured ma ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。