gpt4 book ai didi

ios - 如果找到匹配正则表达式,则从字符串中获取值

转载 作者:行者123 更新时间:2023-11-29 12:32:55 30 4
gpt4 key购买 nike

假设我有一个这样的字符串列表:

Hello Word 132 132 132 GoodBye!! Should return 132132132

Hello Word 132 132 GoodBye!! Should return nil

132 132 132 GoodBye! Should return 132132132

132132132 GoodBye! Should return 132132132

1321321321GoodBye! Should return nil

132 132 1321 Should return nil

我如何检查该短语是否有 9 个跟随算法,或由空格分隔,并得到相同的数字?

谢谢

最佳答案

你可以使用这个正则表达式

(\d{3})(\s?\1){2}

并删除匹配中的所有空格。

DEMO顺便说一句,如果你不想匹配

Some123 123 123Thing

你可以使用单词边界 \b(\d{3})(\s?\1){2}\b

关于ios - 如果找到匹配正则表达式,则从字符串中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27174338/

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