textBoundary
说明
示例
匹配文本的边界
使用 textBoundary
匹配文本的开头或结尾。
创建一个包含多段文本的字符串数组。创建一个匹配每段文本的第一个单词的模式。
txts = ["This is the first piece of text" "Here is the second" "Now there are three"]; pat = textBoundary + lettersPattern;
提取该模式。
firstWords = extract(txts,pat)
firstWords = 3x1 string
"This"
"Here"
"Now"
匹配文本的结尾边界
使用 textBoundary
的 "end"
选项匹配一段文本的指定端点。
创建一个包含多段文本的字符串数组。创建一个匹配每段文本的最后一个单词的模式。
txts = ["This is the first piece of text" "Here is the second" "Now there are three"]; pat = lettersPattern + textBoundary("end");
提取该模式。
lastWords = extract(txts,pat)
lastWords = 3x1 string
"text"
"second"
"three"
对文本的边界求反
使用 ~
运算符对 textBoundary
求反。当两个字符都不是文本的开头或结尾时,该模式匹配这两个字符之间的边界。
创建一个包含多段文本的字符串数组。创建一个模式,该模式匹配一段文本中既不在其开头也不在其结尾的字母。
txts = ["This text is first" "Here is the second" "Now there are three"]; pat = ~textBoundary + lettersPattern + ~textBoundary;
提取该模式。
lastWords = extract(txts,pat)
lastWords = 3x4 string
"his" "text" "is" "firs"
"ere" "is" "the" "secon"
"ow" "there" "are" "thre"
输入参数
type
— 边界类型
'either'
(默认) | 'start'
| 'end'
边界类型,指定为 'start'
、'end'
或 'either'
。
数据类型: char
| string
扩展功能
基于线程的环境
使用 MATLAB® backgroundPool
在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool
加快代码运行速度。
版本历史记录
在 R2020b 中推出
另请参阅
pattern
| contains
| extract
| split
| lineBoundary
| lookAheadBoundary
| lookBehindBoundary
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)