正则表达式匹配一个或多个反斜杠和 +迹象

发布于 2024-11-08 17:40:51 字数 215 浏览 0 评论 0原文

我正在编写一个正则表达式来匹配一个或多个 \ 和一个或多个 + 符号。 这是我到目前为止所拥有的,它看起来不正确

/\\+\++/

my $test = "\+";

if( $test =~ /\\+\++/)
{

    print "yes";

}

我已经尝试过这段代码,但它不起作用

I am writing a regular expression to match one or more \ and one or more + signs.
This is what I have so far and it doesn't look like its right

/\\+\++/

my $test = "\+";

if( $test =~ /\\+\++/)
{

    print "yes";

}

Ive tried this code and it doesn't work

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

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

发布评论

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

评论(2

小…楫夜泊 2024-11-15 17:40:51

对我来说看起来不错:

perl -Dr -e '"\\+++" =~ /\\+\++/'
Compiling REx "\\+\++"
rarest char + at 1
rarest char \ at 0
Final program:
   1: PLUS (4)
   2:   EXACT <\\> (0)
   4: PLUS (7)
   5:   EXACT <+> (0)
   7: END (0)
anchored "\" at 0 floating "\+" at 0..2147483647 (checking floating) plus minlen 2
Omitting 

对我来说看起来不错:

amp; 
 support.

EXECUTING...

Guessing start of match in sv for REx "\\+\++" against "\+++"
Found floating substr "\+" at offset 0...
Found anchored substr "\" at offset 0...
Guessed: match at offset 0
Matching REx "\\+\++" against "\+++"
   0 <> <\+++>               |  1:PLUS(4)
                                  EXACT <\\> can match 1 times out of 2147483647...
   1 <\> <+++>               |  4:  PLUS(7)
                                    EXACT <+> can match 3 times out of 2147483647...
   4 <\+++> <>               |  7:    END(0)
Match successful!
Freeing REx: "\\+\++"

Looks fine to me:

perl -Dr -e '"\\+++" =~ /\\+\++/'
Compiling REx "\\+\++"
rarest char + at 1
rarest char \ at 0
Final program:
   1: PLUS (4)
   2:   EXACT <\\> (0)
   4: PLUS (7)
   5:   EXACT <+> (0)
   7: END (0)
anchored "\" at 0 floating "\+" at 0..2147483647 (checking floating) plus minlen 2
Omitting 

Looks fine to me:

amp; 
 support.

EXECUTING...

Guessing start of match in sv for REx "\\+\++" against "\+++"
Found floating substr "\+" at offset 0...
Found anchored substr "\" at offset 0...
Guessed: match at offset 0
Matching REx "\\+\++" against "\+++"
   0 <> <\+++>               |  1:PLUS(4)
                                  EXACT <\\> can match 1 times out of 2147483647...
   1 <\> <+++>               |  4:  PLUS(7)
                                    EXACT <+> can match 3 times out of 2147483647...
   4 <\+++> <>               |  7:    END(0)
Match successful!
Freeing REx: "\\+\++"
已下线请稍等 2024-11-15 17:40:51

您的表达式按原样就可以了,但如果整个字符串仅由 \ & 组成,您可能需要添加锚点。 + 字符。

/^\\+\++$/g

You're expression is fine as is, though you may want to add anchors if the whole string should be made up of only \ & + characters.

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