gpt4 book ai didi

objective-c - 正则表达式用html粗体标记替换星号字符

转载 作者:太空狗 更新时间:2023-10-30 03:57:18 27 4
gpt4 key购买 nike

有没有人有好的正则表达式来做到这一点?例如:

This is *an* example

应该变成

This is <b>an</b> example

我需要在 Objective C 中运行它,但我自己或许可以解决这个问题。正则表达式给我带来了麻烦(生锈了......)。这是我到目前为止所拥有的:

s/\*([0-9a-zA-Z ])\*/<b>$1<\/b>/g

但是好像不行。有任何想法吗?谢谢:)

编辑:感谢您的回答 :) 如果有人想知道在 Objective-C 中使用 RegexKitLite 会是什么样子:

NSString *textWithBoldTags = [inputText stringByReplacingOccurrencesOfRegex:@"\\*([0-9a-zA-Z ]+?)\\*" withString:@"<b>$1<\\/b>"];

再次编辑:实际上,为了包含更多粗体字符,我将其更改为:

NSString *textWithBoldTags = [inputText stringByReplacingOccurrencesOfRegex:@"\\*([^\\*]+?)\\*" withString:@"<b>$1<\\/b>"];

最佳答案

你为什么不做 \*([^*]+)\*并将其替换为 <b>$1</b>

关于objective-c - 正则表达式用html粗体标记替换星号字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6182070/

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