douxingti9307 2015-03-22 13:28
浏览 137
已采纳

正则表达式捕获至少有一个小写字母的单词

I'm trying to capture words in a string like:

1vTvFpU
KOoy6Cc

With regex pattern:

\b(?=(?:.*?[a-z]){1,})[A-Za-z0-9\/\-_.]{7,7}\b

But I have a problem because it also matches words like:

FDSFDFI
WEWEFDP
RRRRRRR

In a string:

FDSFDFI sdfdfdf
WEWEFDP traliii
RRRRRRR sdfdfdf

What Am I doing wrong?

  • 写回答

2条回答 默认 最新

  • dpsr1670 2015-03-22 13:30
    关注

    I suggest you to use \S* instead of .* inside the lookahead. Because when you include .*? inside the lookahead, it checks for atleast one lower-case letter for the whole line not for the word.

    \b(?=(?:\S*?[a-z]))[A-Za-z0-9\/\-_.]{7}\b
    

    {7,7} is equal to {7}

    DEMO

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥66 定制开发肯德基自动化网站下单软件
  • ¥20 vscode虚拟环境依赖包未安装
  • ¥15 odoo17关于owl开发js代码问题
  • ¥15 光纤中多普勒频移公式的推导
  • ¥15 怎么制作一个人脸识别门禁系统
  • ¥20 大华dss监控平台网络关闭登不进去
  • ¥15 请使用蚁群算法解决下列问题,并给出我完整的代码
  • ¥20 关于php录入完成后,批量更新数据库
  • ¥15 请教往复密封润滑问题
  • ¥15 cocos creator发布ios包