[英]regular expression: matching does not contain specific string
By using a regular expression I want to get all indexes where the following character sequence appears: 通过使用正则表达式,我想获得出现以下字符序列的所有索引:
FORALL ... in ... :
// between "FORALL" and "in" might be whitespaces and non-word characters like "," //“FORALL”和“in”之间可能是空格和非单词字符,如“,”
example: find these 3 ones: 示例:找到这3个:
replace with this one: 替换为这一个:
FORALL i,j in a1: FORALL i,j in a1:
part of the idea: 部分想法:
the substring has to start with the word FORALL 子字符串必须以单词FORALL开头
the "in" respectively the ":" has to appear exactly one time - therefore do not get by mistake the "in" from the actual next independent match “in”和“:”必须恰好出现一次 - 因此不要错误地从实际的下一次独立比赛中得到“in”
inside of the substring is no "in" allowed but the first part should end with one 子串内部不允许“in”,但第一部分应以一个结束
My last trying is the following regular expression 我的最后一次尝试是以下正则表达式
"(^FORALL[<=|>=|<|>|==|!=](?!.*in).*in$)((?!.*\\:).*\\:$ )"
according: Regular expression that doesn't contain certain string 依据: 正则表达式,不包含某些字符串
You could maybe give this regex a try? 你可以试试这个正则表达式吗? (it's a literal string) (这是一个文字字符串)
^(FORALL [^<=>,: ]+) *[<=>,]+ *([^<=>,: ]+)\s+in\s+([^,:]+)[^:]*:$
Here's a breakdown: 这是一个细分:
^ # Beginning of string
( # 1st capture begins
FORALL # Match FORALL and a space
[^<=>,: ]+ # Any characters except <=>,: or space
) # 1st capture ends
* # Any spaces
[<=>,]+ * # Any characters of <=>, followed by any spaces
( # 2nd capture begins
[^<=>,: ]+ # Any characters except <=>,: or space
) # 2nd capture ends
+in + # Match in surrounded by spaces
([^,:]+) # Match any non , or : characters
[^:]*: # Match any non : characters, then match a :
$ # End of string
And replace with: 并替换为:
$1,$2 in $3:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.