lineBoundary
匹配行首或行尾
说明
示例
匹配行的边界
使用 lineBoundary
匹配一行文本的开头或结尾。
创建一个包含 newline
字符的字符串。创建一个模式,它匹配新行开头后的字母。
txt = "This is line one." + newline + "Here is line two."; pat = lineBoundary + lettersPattern;
提取该模式。
firstWord = extract(txt,pat)
firstWord = 2x1 string
"This"
"Here"
匹配行的开头和结尾边界
使用 lineBoundary
的 "start"
选项来匹配行的指定端点。
创建一个包含 newline
字符的字符串。创建一个模式,它匹配行的两个 "start"
边界之间的任何字符。
txt = "This is line one." + newline + "Here is line two." + newline + "Last but not least."; pat = lineBoundary("start") + wildcardPattern(1,inf) + lineBoundary("start");
提取该模式。
extract(txt,pat)
ans = 2x1 string
"This is line one...."
"Here is line two...."
对行的边界求反
使用 ~
运算符对 lineBoundary
求反。
当两个字符都不是 newline
字符时,该模式匹配这两个字符之间的边界。
创建一个包含 newline
字符的字符串。创建一个匹配字母的模式,这些字母既不在一行文本的开头也不在末尾。
txt = "This is line one" + newline + "Here is line two"; pat = ~lineBoundary + lettersPattern + ~lineBoundary;
提取该模式。
firstWord = extract(txt,pat)
firstWord = 8x1 string
"his"
"is"
"line"
"on"
"ere"
"is"
"line"
"tw"
输入参数
type
— 边界类型
'either'
(默认) | 'start'
| 'end'
边界类型,指定为 'start'
、'end'
或 'either'
。
数据类型: char
| string
版本历史记录
在 R2020b 中推出
另请参阅
pattern
| contains
| extract
| split
| textBoundary
| 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)