我想使用bash脚本取消注释一行。通常我使用perl命令来替换文本,但在这种情况下,这不起作用:
def main():
# change string to strings accordingly
number, strings = get_inputs()
# change result to result in a way similar to
# the change of `string -> strings` in `get_inputs()`.
results = [is_palindrome(string) for string in strings]
for result in results:
report(result)
# We could write [report(result) for result in results] here.
# But we are not interested in the result list
# The result list will be [None, None, ...].
# So this is side-effects only.
# A for loop is usually preferred for side-effects only,
# and list comprehension for building a list.
提前致谢。
答案 0 :(得分:2)
(
和)
是正则表达式元字符,它们具有特殊含义; they mean to capture what's inside it
/# %wheel ALL=(ALL) NOPASSWD: ALL/
与# %wheel ALL=(ALL) NOPASSWD: ALL
不匹配。它会匹配# %wheel ALL=ALL NOPASSWD: ALL
(请注意缺少parens)并在ALL
中捕获$1
。
您可以使用\
之类的/# %wheel ALL=\(ALL\) NOPASSWD: ALL/
转义任何特殊元字符,也可以声明在\Q
和\E
之间按字面意思取消所有内容。 /\Q# %wheel ALL=(ALL) NOPASSWD: ALL\E/