我正在寻找一个正则表达式来替换括号中的所有项,除非括号在方括号内。
例如:
(matches) #match
[(do not match)] #should not match
[[does (not match)]] #should not match
我目前有:
[^\]]\([^()]*\) #Not a square bracket, an opening bracket, any non-bracket character and a closing bracket.
然而,这仍然是方括号中的匹配单词。
到目前为止,我还创建了我的进度的一个小页面:
有,比方说:
fieldA=20 and (fieldB=date() and (fieldC=35 and fieldD=40)) and fieldE = 100
我试着用“和”字来代替,什么的:
fieldA=20 zzz (fieldB=date() and (fieldC=35 and fieldD=40)) zzz fieldE = 100
我试了几个小时,但没有成功。我可以找到一些关于如何把所有东西都放在括号或括号里的答案。下面的表达式包含括号中的所有内容,但实际上我不知道如何编写忽略这一点的表达式:
\(([^()]*+|(?R))*\) # retrieves "
我想替换一下
'this is my string (anything within brackets)'
使用
'this is my string '
一个具体的样本是:
'Blue Wire Connectors (35-Pack)'
应改为
'Blue Wire Connectors '
有人能建议如何在python中构建这个regex吗?
我试图通过使用正则表达式从输入字符串中获取函数。
到目前为止,我使用以下正则表达式成功地获得了:
/(\b(f|F)unction(.*?)\((.*?)\)\s*\{)/g
当像这样应用时,将返回第一个索引的完整声明:
var re = /(\b(f|F)unction(.*?)\((.*?)\)\s*\{)/g;
while ((m = re.exec(text)) !== null) {
//m[0] contains the function declaration
declarations.push(m[0]);
}
现在,我想获得返回的匹配,每个函数的全部内容,以
我正试图匹配<sup>标记中任何括号内的项目。
我的正则表达式太贪婪了,从第一个<sup>标记开始,最后一个</sup>标记结束。
/<sup\b[^>]*>(.*?)\[(.*?)\](.*?)<\/sup>/
示例html:
<sup>[this should be gone]</sup>
<sup>but this should stay</sup>
<sup>this should [ also stay</sup>
[and this as wel
所以假设我有这个
example: 1
[
this shouldn't be matched
]
example : 2
[
some bla
[
other bla
]
]
我观察文件是否有嵌套括号。我不想实际检查括号是否匹配,我只需要看看它们是否存在。
在我的脑海里,听起来很简单,但我无法从这个(正则表达式方面)中得到不作为。
因此,我想出了一些东西(希望是一个扫描器),它只是一个简单的javascrpit函数。
function idNested(str){
// match all brackets
var g = st
下面是我必须匹配的示例字符串:
var sampleStr = "aaa[bbb=55,zzz=ddd],#ddd[ppp=33,kk=77,rr=fff],tt,ff";
我需要编写与所有,字符匹配的regex,这些字符不在[ ]中。
因此,在我的示例字符串中,我应该接收下一个,字符:
- `,` before `#ddd`
- `,` before `tt`
- `,` before `ff`
它应该忽略下一个,
- `,` before `zzz`
- `,` before `kk`
- `,` before `rr`
实际上,我不知道
我正在开发一个使用正则表达式的数学表达式解析器,并尝试添加对括号的支持。
我的解析器是这样工作的:
function parse_expression(expression){
Find parenthetical expressions
Loop through parenthetical expressions, call parse_expression() on all of them
Replace parenthetical expression with value of expression
Find value of expression
我想知道eregi_replace的正则表达式需要什么才能捕获没有包含在alt属性中的字符串。
例如,它应该在以下位置找到并替换John Doe:
“无名氏出生于...”
但不能在John Doe在任何标签中时查找/替换,例如:
<img src="/jd.jpg" alt="John Doe at the beach" />
我正在使用re,但我没有任何运气。我想知道如何删除大括号之间的空格。例如
我有这个字符串
i want to go to the[ super mall ](place)
你看到“超级商场”里的空位了吗?
什么可以将这个字符串转换为
i want to go to the [super mall](place)
我很感激在这方面能得到的任何帮助,谢谢。
有没有可能编写一个正则表达式来匹配出现次数未知的嵌套模式?例如,当一个正则表达式的左大括号和右大括号中嵌套了未知数量的左/右大括号时,该正则表达式是否可以匹配这两个大括号?
例如:
public MyMethod()
{
if (test)
{
// More { }
}
// More { }
} // End
应匹配:
{
if (test)
{
// More { }
}
// More { }
}
我试图用{和}之间的实际空格替换html实体为空白。
示例示例
"this is a gap {{ for user in users }}" =>
"this is a gap {{ for user in users }}"
我找到了类似的答案,这促使我写了这样的东西(这是行不通的)
.gsub(/(?<=\{\{).*( ?).*(?=\}\})/