正则表达式匹配到给定的文本?

2024-04-26 04:25:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在写一个正则表达式,它将匹配fooSVM??!。我想在这个字符串中匹配SVM,这意味着我需要从foo匹配到满足?!。注意SVM可以是其他Unicode字符。你知道吗

我试过foo(.*)[?!]*,但似乎不起作用。你知道吗


Tags: 字符串foounicode字符svmfoosvm
1条回答
网友
1楼 · 发布于 2024-04-26 04:25:29

如果没有换行符,则可以这样做:

foo([^?!]+)[?!]

检索第一组。你知道吗

foo        # Find "f", then "o", then "o",
(          # begin capture
    [^?!]  # followed by any character which is not "!" or "?",
    +      # once or more
)          # end capture
[?!]       # followed by either a "!" or a "?"

相关问题 更多 >