加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何编写正则表达式以匹配标题案例句子(例如:我喜欢工作)

发布时间:2020-12-14 06:26:50 所属栏目:百科 来源:网络整理
导读:我需要找到一个匹配每个句子的正则表达式,无论它是否跟随标题大小写(句子的每个单词的第一个字母应该是大写的,并且单词也可以包含特殊字符). regex101 ([A-Z][^s]*) Debuggex Demo 描述 1st Capturing group ([A-Z][^s]*) [A-Z] match a single character
我需要找到一个匹配每个句子的正则表达式,无论它是否跟随标题大小写(句子的每个单词的第一个字母应该是大写的,并且单词也可以包含特殊字符).
regex101
([A-Z][^s]*)

Debuggex Demo

描述

1st Capturing group ([A-Z][^s]*)  
    [A-Z] match a single character present in the list below  
        A-Z a single character in the range between A and Z (case sensitive)
    [^s]* match a single character not present in the list below
        Quantifier: * Between zero and unlimited times,as many times as possible,giving back as needed [greedy]
        s match any white space character [rntf ]
g modifier: global. All matches (don't return on first match)

Full Sentence

^(?:[A-Z][^s]*s?)+$

Debuggex Demo

描述

^ assert position at start of the string
(?:[A-Z][^s]*s?)+ Non-capturing group
    Quantifier: + Between one and unlimited times,giving back as needed [greedy]
    [A-Z] match a single character present in the list below
        A-Z a single character in the range between A and Z (case sensitive)
    [^s]* match a single character not present in the list below
        Quantifier: * Between zero and unlimited times,giving back as needed [greedy]
        s match any white space character [rntf ]
    s? match any white space character [rntf ]
        Quantifier: ? Between zero and one time,giving back as needed [greedy]
$assert position at end of the string

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读