- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我想捕获匹配的大括号。
例如:
Some example text with \added[author]{text with curly braces{some text}..}
Some example text with \added[author]{text without curly braces}
Some example text with \added[author]{text with {}and {} and {}curly braces{some text}..}
Some example text with \added[author]{text with {}and {} and {}curly braces{some text}..} and extented text with curly braces {}
预期输出:
Some example text with text with curly braces{some text}..
Some example text with text without curly braces
Some example text with text with {}and {} and {}curly braces{some text}..
Some example text with text with {}and {} and {}curly braces{some text}.. and extented text with curly braces {}
即我想捕获 \added[]{
之间的文本和 }
(它的相对闭合花括号)。我的正则表达式的问题是,我不知道如何在相关的花括号之间进行捕获。
我试过了,
"/\\\\added\\[.*?\\]{(.[^{]*?)}/s"
我知道它会忽略 if {
出现在文中。但我不知道如何创建一个正则表达式来单独匹配花括号。
最佳答案
在这里,应该工作
/\\added\[.*\]\{(.*(?:.*\{.*\}.*)*)\}/gU
解释
/\\added\
是一个Latex标签,
\[.*\]
是Latex标签的一个选项,
\{
左括号,
(.*(?:.*\{.*\}.*)*)
是捕获的文本,我们在这里也防止递归 {...}
或目标标签内的多个 {...}
,
\}
右括号。
策略
我不认为括号对是递归形式
{ { {...} } }
c b a a b c
我们有对 a
、b
和 c
,
但我认为他们是这样的!
{ { {...} } }
a b c a b c
参见:DEMO
我的demo中的最后两个例子也证明了它可以正常工作。
重要修饰符 U
应该在这里用于非贪婪量词,否则我的正则表达式将无法正常工作。
关于php - 正则表达式:捕获成对的花括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32329190/
我用 redis 后端运行 celery。 我想在 centos 6.2 上运行 celery 花作为守护进程。 我知道花是 Tornado 应用程序,所以我应该使用一个进程来运行 Tornado 应
我在一台服务器上有几个项目,它们使用具有不同 BROKER_URL 的 celery 包。Flower 允许一个 BORKER_URL 作为命令选项: celery flower --broker=a
我正在使用芹菜和花卉。当我访问Flower中的“任务”标签时,我可以看到我的任务正在注册,甚至可以在“状态”列中看到“成功”标签以及所有内容。 但是,在“监视器”选项卡上,所有图形(“成功任务”,“失
我正在尝试创建一个有 5 个叶子的 css 花 - 没有任何有希望的尝试。我正在尝试创建什么:有 5 片叶子的 CSS 花,每片叶子可以有三种不同的状态(小、中、大)。我找到了 http://ross
如果我有一个变体,像这样: using my_variant = boost::variant; 有没有一种简单的方法可以将变体可以包含的类型提取到 Boost.Hana 元组中,以便满足以下条件:
调用 Flower API's /api/task/apply/* 只是挂起而没有返回结果,即使任务已根据 Web UI 处理并成功。 重现错误: # hangs even though task s
我有一个模板函数,默认情况下没有定义,但它由某些类型特化: template auto foo(bar &, const T &) -> void; template <> auto foo(bar
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
我是一名优秀的程序员,十分优秀!