开发者

Regexp to find strings enclosed by ** (double-star)

开发者 https://www.devze.com 2023-03-26 13:32 出处:网络
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.

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 开发者_如何学Pythonsit and semper and I really don't know how to manage it.


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.


You can do it like this..

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号