异常处理机制如何在.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
最满意答案
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
causesre.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^
.
相关问答
更多-
Python正则表达式(Python regular expression)[2023-04-27]
\{\#([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 ...
-
Ruby正则表达式在Perl中是否具有类似“!〜”的运算符?(Does Ruby regular expression have a not match operator like “!~” in Perl?)[2023-06-20]
是的: !~工作很好 - 你可能以为没有,因为它从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 个人模式看起来非常混乱,所以我不知道什么是错误,什么是故意的。 我猜你正在几个不同的环境 ...
-
使用Python正则表达式捕获组的所有重复(Capture all repetitions of a group using Python regular expression)[2022-07-03]
通过简单的字符串操作,您可以更清楚地了解它。 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 ...