[英]How to remove characters from a string until a special character?
I have a string like this.我有一个这样的字符串。
config =\
{"status":"None",
"numbers":["123", "123", "123"],
"schedule":None,
"data":{
"x": "y"
}
}
I would like to remove the config=\\ from the string and get a result like this.我想从字符串中删除 config=\\ 并得到这样的结果。
{"status":"None",
"numbers":["123", "123", "123"],
"schedule":None,
"data":{
"x": "y"
}
}
How can I get this using python regex?我怎样才能使用 python regex 得到这个? Would like to consider the multiline factor as well!!也想考虑多线因素!!
I am using this method我正在使用这种方法
re.sub(r'.*{"', '{"', script_config, flags=re.MULTILINE)
But the code consider each line separately.但是代码分别考虑每一行。 Also I would like to remove only the我也想只删除
You don't need regexp for it:你不需要正则表达式:
string = string.replace('config =\\\\', '')
If the first word is not specified:如果未指定第一个单词:
string = string[string.find('\\\\')+1:] if '\\\\' in string else string
But if you want to use regexps:但是如果你想使用正则表达式:
string = re.sub(r'^.*\\\\', '', string)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.