好吧,是这样的:
I'm writing a huge programming file, and, while near the end, I realize that I made a stupid mistake. Basically, the text looks like this now: "usable_by"
{
//Here is a line(s) that looks like the following:
"one" "1"
"two" "1"
//It can have any combination of these lines, with "one" or "two" in the lines above going up to nine.
} 评论显然不是程序的一部分,是你的笔记,以帮助我。
我希望将这些实例替换为所有九个属性,因此如下所示:
{
"one" "1"
...
"nine" "1"
}和..。是2-8岁。
我猜您将不得不设计一种方法来替换{和}之间的任何东西(但只在"usable_by“标记上,以便其他标记不会被破坏)。
任何帮助都是非常感谢的。此外,我希望你能解释它,而不是仅仅给我这条正则线可能是什么。
谢谢!
发布于 2014-08-27 01:11:48
拜托,拜托,在运行之前备份一下你的资料。它对我有效,但我只有一点点的样本文本。
找出什么:
("usable_by"\s*\{\s*\n)(\s*)[^}]*\n(\s*)代之以:
\1\2"one" "1"\n\2"two" "1"\n\2"three" "1"\n\2"four" "1"\n\2"five" "1"\n\2"six" "1"\n\2"seven" "1"\n\2"eight" "1"\n\2"nine" "1"\n\3Regex细分:
( # Start of first capturing group. Save for use in the replacement.
"usable_by" # This should be obvious.
\s* # \s match any whitespace character, the * means "zero or more."
\{ # The opening curly brace.
\s* # More optional additional space.
\n # Newline.
) # End of first capturing group.
(\s*) # Second capturing group. Grabs the attribute indentation.
[^}]* # Everything up to the closing curly brace.
# Except it'll backtrack a bit so we can get rid of the next two.
\n # Newline, the last before your final } line.
(\s*) # Third capturing group. Picks up the indentation
# leading up to the closing curly brace.更换细目:
\1 # Back-reference to the first capturing group. Puts it here.
\2 # And the second, your indentation. We'll reuse this a bunch.
"one" "1" # Your first attribute.
\n # A newline
\2 # There's your indentation again.
"two" "1" # And second attribute.
\n # And newline.
... # etc. don't really need to explain them all individually.
\2"nine" "1"\n # Indentation, ninth attribute, newline.
# You're used to all this by now.
\3 # The third capturing group. The indentation leading
# up to your closing }.https://stackoverflow.com/questions/25517151
复制相似问题