“匹配”的含义 与正则表达式相关

发布于 2024-07-13 20:59:53 字数 218 浏览 6 评论 0原文

我正在写一篇关于正则表达式的学期论文,对于人们在引用正则表达式时使用“匹配”一词的方式有点困惑。 以下哪一个是正确的措辞:

  • “正则表达式与字符串匹配”

  • “字符串与正则表达式匹配”

或者它们都正确? 欢迎对此提出任何意见! 我真的很想弄清楚这一点,并且我认为澄清这一点将极大地帮助我的理解。

I'm writing a term paper on regular expressions and I'm a bit confused regarding the way one uses the word "match" when referring to regexes. Which of the following is the correct wording to use:

  • "The regular expression matches the string"

or

  • "The string matches the regular expression"

Or are they both correct? All opinions on this are welcome! I really want to get this right and I think it would help my understanding greatly to get this clarified.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

小巷里的女流氓 2024-07-20 20:59:53

我认为两者都是正确的。 这取决于你关注的重点。 如果您的重点是正则表达式本身,看看它是否适用于给定的字符串或字符串集,那么您可以使用第一句话。 相反,如果您更感兴趣的是查看一组符合特定条件的字符串,则第二个适用。 你知道,匹配在某些条件下具有某种等价的含义,所以这两个句子听起来对我来说都是等价的。

I think both are correct. It depends on what you're focusing on. If your focus is in the regular expression itself to see if it serves to work on a given string or set of strings, then you use the first sentence. In the contrary, if you are more interested in looking at a set of strings that match certain criteria, the second one is applicable. You know, a match has the meaning of some equivalence under certain conditions, so both sentences sound equivalent to me.

娜些时光,永不杰束 2024-07-20 20:59:53

该字符串正在与正则表达式模式匹配,因此我认为后者更准确

The string is being matched to the regular expression pattern, therefore I would say the latter is more accurate

豆芽 2024-07-20 20:59:53

当两件事匹配时,(至少从逻辑角度来看)你提到它们的顺序是无关紧要的。

所以这取决于你想把重点放在什么上。

字符串与正则表达式匹配:焦点位于字符串上。

正则表达式与字符串匹配:重点是正则表达式。

When two things match, it is (from a logical perspective at least) irrelevant in which order you mention them.

So it depends on what you want to put focus on.

The string matches the regular expression: Focus is on the string.

The regular expression matches the string: Focus is on the regex.

小…楫夜泊 2024-07-20 20:59:53

后者对我来说听起来更好。 正则表达式指定字符串可以匹配的模式。 但两者都没有什么问题。

The latter sounds better to me. The regex specifies a pattern that the string may match. But there's nothing really wrong with either.

小苏打饼 2024-07-20 20:59:53

如果你对我说其中任何一个,我都会明白你在说什么。 我确信人们都对我说过这两句话,但我从不认为其中任何一个需要纠正。

If you said either one to me, I would understand what you're saying. I'm sure people have said both to me, and I never thought either one needed to be corrected.

思念满溢 2024-07-20 20:59:53

我同意该字符串与正则表达式匹配(或不匹配)。 为了弄清楚为什么我会说:正则表达式定义了一种语法,并且给定的字符串根据该语法要么是格式良好的,要么不是。

I agree that the string matches (or not) the regular expression. To make it clear why I'd say: the regular expression defines a grammar, and a given string is either well-formed according to that grammar or not.

回忆凄美了谁 2024-07-20 20:59:53

“正则表达式匹配字符串”
如果 RE 匹配整个字符串(例如使用 ^ $ 或恰好匹配所有内容),则为 True。 否则,我会写:正则表达式在字符串中有匹配项。

“字符串与正则表达式匹配”
再说一次,如果正则表达式匹配所有内容,则为 true,否则听起来有点奇怪。
但事实上,在整场比赛的情况下,这两个句子是等价的。

"The regular expression matches the string"
True if the RE matches the whole string (eg. using ^ $ or just happening to match everything). Otherwise, I would write: the regular expression has match(es) in the string.

"The string matches the regular expression"
Again, true if the regex matches everything, otherwise it sounds a bit odd.
But indeed, in the case of a whole match, the two sentences are equivalent.

挽梦忆笙歌 2024-07-20 20:59:53

由于您正在字符串中查找正则表达式,因此更正确的说法是您已找到正则表达式,因为这是一种单向关系。

但至于哪个与哪个匹配,这是一种双向关系,并不重要(无论如何,用英语 - 我不能保证其他语言),所以两者都是正确的。

我的偏好是字符串与正则表达式匹配,因为 RE 是不变部分并且字符串会发生变化。 但这是个人偏好,不太可能与现实产生任何影响:-)

Since you're looking for a regular expression within a string, it's more correct to say that you've found the regular expression since that's a one-way relationship.

But as to which matches which, that's a two way relationship and it doesn't really matter (in English, anyway - I can't vouch for other languages ), so either would be correct.

My preference would be to say that the string matches the regular expression, since the RE is the invariant part and the string changes. But that's a personal preference and is unlikely to have any bearing on reality :-)

救星 2024-07-20 20:59:53

“字符串与正则表达式匹配”似乎是“字符串采用正则表达式定义的语言并且与正则表达式同构”的简写。

“正则表达式与字符串匹配”似乎是“从正则表达式编译的解析器自动机将解析字符串并停止在最终状态”的简写。

"The string matches the regular expression" seems to be shorthand for "the string is in the language defined by and isomorphic to the regular expression."

"The regular expression matches the string" seems to be shorthand for "a parser automaton compiled from the regular expression will parse the string and halt in a final state."

时光病人 2024-07-20 20:59:53

我会说:

设计时,用户/开发者创建一个与字符串匹配的正则表达式

运行时,正则表达式引擎会查找与正则表达式匹配的字符串

(无意作为定义,只是常见用法的示例。)

I'd say:

At design time a user/develper creates a regular expression that matches a string.

At run time a regular expression engine finds a string that matches the regular expression.

(Not intended to be a definition, just an example of common usage.)

暖树树初阳… 2024-07-20 20:59:53

由于正则表达式表示可能无限的有限字符串集,因此我认为最正确的写法是“字符串 s 与正则表达式 r 匹配”。 您也可以说“字符串 s 是正则表达式 r 生成的集合的成员”。

另外,您应该考虑使用单词接受拒绝,特别是如果您打算在论文中讨论有限自动机。

Since a regular expression represents a possibly infinite set of finite strings, I would say that it is most correct to write that "string s matches regular expression r". You could also say that "string s is member of the set generated by regular expression r".

Also, you should consider using the words accept and reject, especially if you intend to discuss finite automata in your paper.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文