matlab里comb用法,comb - 操作字符串的利器

comb - 操作字符串的利器

comb 子例程

comb 子例程的定义为:

multi sub comb(Regex $matcher, Str(Cool) $input, $limit = *) returns List:D

multi method comb(Regex $matcher, $limit = *) returns List:D

用法:

comb /PATTERN/, STRING, LIMIT? # 子例程形式

STRING.comb(/PATTERN/, LIMIT?) # 方法形式

返回调用者(方法形式)的所有(或者至多 $limit 个,如果提供了的话)匹配,或者返回第二个参数(sub 形式)与 Regex 相匹配的字符串列表。

say "6 or 12".comb(/\d+/).join(", "); # 6, 12

Str 类中的 comb

multi sub comb(Str:D $matcher, Str:D $input, $limit = Inf)

multi sub comb(Regex:D $matcher, Str:D $input, $limit = Inf, Bool :$match)

multi sub comb(Int:D $size, Str:D $input, $limit = Inf)

multi method comb(Str:D $input:)

multi method comb(Str:D $input: Str:D $matcher, $limit = Inf)

multi method comb(Str:D $input: Regex:D $matcher, $limit = Inf, Bool :$match)

multi method comb(Str:D $input: Int:D $size, $limit = Inf)

在 $input 中搜索 $matcher 并返回所有匹配(默认是 Str,或者是 Match 对象,如果 $match 为真的话)的一个列表。$limit 表示至多返回 $limit 个匹配。

如果没有提供 $matcher(匹配器), 那么会返回字符串中的所有字符的列表。等价于使用了 $matcher = rx/./。

例子:

comb(/\w/, "a;b;c").perl; # ("a", "b", "c").list

comb(/\N/, "a;b;c").perl; # ("a", ";", "b", ";", "c").list

comb(/\w/, "a;b;c", 2).perl; # ("a", "b").list

comb(/\w\;\w/, "a;b;c", 2).perl; # ("a;b",).list

"123abc456def".comb(3) # (123 abc 456 def)

"123abc456def".comb(3,2); # (123 abc)

如果匹配器(matcher)是一个整数值,那么它被认为和 /. ** matcher/ 类似,但是这个快了 30 倍。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值