正则表达式查找由 **(双星)括起来的字符串

发布于 2024-11-28 06:48:37 字数 370 浏览 2 评论 0原文

我正在尝试找到一种方法来从字符串中生成匹配模式的数组。 我将用一个例子来解释自己。

从像我这样的字符串中,

Lorem ipsum dolor **sit** amet, consectetur adipiscing elit. 
Nulla elementum euismod mi. Morbi eu eros eget augue vestibulum semper. 
Curabitur sapien purus, **semper** in consequat eu, gravida vitae purus.

我需要应用正则表达式来提取单词 sitsemper 我真的不知道如何管理它。

I'm trying to find a way to make an array of matched patterns out of a string.
I'll explain myself with an example.

From a string like

Lorem ipsum dolor **sit** amet, consectetur adipiscing elit. 
Nulla elementum euismod mi. Morbi eu eros eget augue vestibulum semper. 
Curabitur sapien purus, **semper** in consequat eu, gravida vitae purus.

I need to apply a regexp to extract the words sit and semper
and I really don't know how to manage it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我的奇迹 2024-12-05 06:48:37

我认为像 \*{2}(.*?)\*{2} 这样的正则表达式会处理它,并在 Objective-C 中使用正则表达式(假设你在一个Apple 平台)您需要查看 NSRegularExpression iOSMac 文档。

I would think a regex such as \*{2}(.*?)\*{2} would take care of it, and using regular expressions in Objective-C (assuming you're on an Apple platform) you'd want to look at the NSRegularExpression iOS or Mac documentation.

情何以堪。 2024-12-05 06:48:37

你可以这样做..

\s*{2}([^\*]+)\s*{2}

You can do it like this..

\s*{2}([^\*]+)\s*{2}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文