欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 建筑 > MATLAB中textBoundary函数用法

MATLAB中textBoundary函数用法

2025/2/2 20:05:16 来源:https://blog.csdn.net/jk_101/article/details/133668875  浏览:    关键词:MATLAB中textBoundary函数用法

目录

语法

说明

示例

匹配文本的边界

匹配文本的结尾边界

对文本的边界求反


        textBoundary函数的功能是匹配文本的开头或结尾。

语法

pat = textBoundary
pat = textBoundary(type)

说明

        pat = textBoundary 创建与文本开头或结尾匹配的模式。textBoundary 可以使用 ~ 运算符求反。当求反时,textBoundary 匹配除文本开头或结尾以外的每个字符之间的边界。

        pat = textBoundary(type) 指定是匹配文本的开头还是结尾。type 可以是 'start'、'end' 或 'either'(默认值)。

示例

匹配文本的边界

        使用 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 — 边界类型

        边界类型,指定为 'start'、'end' 或 'either'。

pat — 模式表达式

        模式表达式,以 pattern 对象形式返回。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com