简单的正则表达式问题.我有一个以下格式的字符串:
this is a [sample] string with [some] special words. [another one]
Run Code Online (Sandbox Code Playgroud)
提取方括号内的单词的正则表达式是什么,即.
sample
some
another one
Run Code Online (Sandbox Code Playgroud)
注意:在我的用例中,括号不能嵌套.
我需要从字符串中提取一组包含在两个分隔符之间的字符,而不返回分隔符本身.
一个简单的例子应该是有用的:
目标:提取方括号之间的子字符串,而不返回括号本身.
基本字符串:This is a test string [more or less]
如果我使用以下reg.恩.
\[.*?\]
比赛是[more or less].我只需要more or less(没有括号).
有可能吗?
regex ×2