gpt4 book ai didi

regex - 获取一个接一个的上标数字作为一个字符串

转载 作者:行者123 更新时间:2023-11-28 08:52:28 24 4
gpt4 key购买 nike

我使用以下代码获取上标数字:

var pattern: NSRegularExpression?
do {
try pattern = NSRegularExpression(pattern: "[¹²³⁴⁵⁶⁷⁸⁹⁰]", options: NSRegularExpressionOptions.CaseInsensitive)
} catch {
print("Error getting pattern")
}

如何从包含两个或更多数字的上标数字中获取字符串,例如 ¹² 等。

最佳答案

你只需要添加一个+量词:

[¹²³⁴⁵⁶⁷⁸⁹⁰]+
^

+ 表示匹配前面的子模式的 1 次或多次出现

参见 the regex demo

查看更多详情 regex quantifiers in the Mastering Quantifiers section at rexegg.com .

A regex quantifier such as + tells the regex engine to match a certain quantity of the character, token or subexpression immediately to its left.

关于regex - 获取一个接一个的上标数字作为一个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33843551/

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