gpt4 book ai didi

regex - 仅在 MATLAB 中的行首匹配正则表达式

转载 作者:太空宇宙 更新时间:2023-11-03 20:13:00 24 4
gpt4 key购买 nike

我有一个跨越多行的字符串。换行符是 LF,如“hello world”示例中的“hello”和“world”之间有一个换行符:

some_bytes = [104  101  108  108  111 10 119  111  114  108  100];
some_string = char(some_bytes);

disp(some_string)

我想匹配序列“wo”,但前提是它出现在一行的开头。但是使用正则表达式

idx = regexpi(some_string,'^wo');

返回一个空数组。我做错了什么?

最佳答案

^,默认情况下,只匹配字符串的开头。您可以使用 (?m) 搜索标志激活多行模式:

idx = regexpi(some_string,'(?m)^wo');

或者,您可以提供选项 'lineanchors'See the documentation .

关于regex - 仅在 MATLAB 中的行首匹配正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18319235/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com