MATLAB 帮助中心
匹配数字字符和非数字字符之间的边界
pat = digitBoundary
pat = digitBoundary(type)
pat = digitBoundary 创建与一系列数字字符的开始或结束相匹配的模式。digitBoundary 可以使用 ~ 运算符求反。当求反时,~digitBoundary 匹配任意两个字符之间的边界,但一系列数字的开始或结束位置除外。
pat
digitBoundary
~
~digitBoundary
示例
pat = digitBoundary(type) 指定匹配一系列数字的开始还是结束位置。type 可以是 'start'、'end' 或 'either'(默认值)。
type
'start'
'end'
'either'
全部折叠
使用 digitBoundary 在数字字符和非数字字符之间的边界处拆分字符串。
创建一个匹配任何数字边界的模式。
txt = "123 abc .?! def 456"; pat = digitBoundary;
使用 replace 在匹配的边界处插入“|”字符。
replace
replace(txt,pat,"|")
ans = "|123| abc .?! def |456|"
使用 digitBoundary 的 "start" 和 "end" 选项来匹配数字与非数字字符之间的边界。
"start"
"end"
创建一个包含几种不同类型字符的字符串。创建一个模式,该模式匹配数字的 "start" 边界和 "end" 边界之间的任何字符。
txt = "123 abc .?! def 456"; pat = digitBoundary("start") + wildcardPattern(1,inf) + digitBoundary("end");
提取该模式。
boundaries = extract(txt,pat)
boundaries = 2×1 string "123" "456"
使用 ~ 运算符对 digitBoundary 求反。当两个字符都是数字字符或都不是数字字符时,此模式匹配这两个字符之间的边界。
创建一个包含几种不同类型字符的字符串。创建一个与求反的 digitBoundary 匹配的模式。
txt = "123 abc .?!"; pat = ~digitBoundary;
使用 replace 插入 "|" 字符以显示与 ~digitBoundary 匹配的位置。
"|"
boundaries = replace(txt,pat,"|")
boundaries = "1|2|3 |a|b|c| |.|?|!|"
边界类型,指定为 'start'、'end' 或 'either'。
数据类型: char | string
char
string
模式表达式,以 pattern 对象形式返回。
pattern
全部展开
backgroundPool
ThreadPool
在 R2020b 中推出
pattern | contains | extract | split | alphanumericBoundary | letterBoundary | whitespaceBoundary
contains
extract
split
alphanumericBoundary
letterBoundary
whitespaceBoundary
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
欧洲
亚太
联系您当地的办事处