gpt4 book ai didi

php - 正则表达式 - 选择具有多个大写字母的行

转载 作者:行者123 更新时间:2023-12-02 12:14:56 25 4
gpt4 key购买 nike

我有一条文字,类似于:

1: hello people on stackoverflow, this here is my sample string
2: to show you what I want to achive. Here are some lines
3: I want to select
4: asdAsasDAqdVGevSerE312d1d14fF2Asdc
5: klhkblkljhb2k324JKgnqwwuUIH82mjkaw
6: heLloIsWhatIwantToSelectToo
7: thisLineshouldnotbeselected
8: butThislineshouldbeselectedasWell
9: and some more lines here...

现在我正在测试几个小时,以获得一个正则表达式来选择具有超过 1 个大写字符且没有空格的行。

所以我想选择行4568

我的所有尝试都匹配具有 2 个大写字母的行,例如 yXXy,但我想选择具有它们的行,例如 XyyXXyXy

这可以用正则表达式实现吗?

稍后需要在 php 中使用它们...

ATM 上的 Smaple RegExp im:

^([a-zA-Z0-9=]?(?! )){2,}$

我确实有更多,但由于我像上面解释的那样进行选择......我不知道该写什么^^

最佳答案

a regexp to select lines having more than 1 uppercased character and no whitespaces.

您可以使用以下正则表达式:

/^\S*[A-Z]\S*[A-Z]\S*$/

Example Here

  • ^ - 表示行开头的 anchor
  • \S* - 零个或多个非空白字符
  • [A-Z] - 大写字符
  • \S*[A-Z]\S* - 大写字符周围有零个或多个非空白字符
  • $ - 表示行尾的 anchor

相应地调整标志。在演示中,我使用全局和多行标志(但 PHP 没有 g 标志)。

关于php - 正则表达式 - 选择具有多个大写字母的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34930671/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com