正则表达式在线替换工具
关于正则表达式在线替换工具:
这个正则表达式在线替换工具可以帮助您替换字符串中符合您的正则化表达式部分.
链接:
Javascript RegExp手册: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
Python re库: https://docs.python.org/3/library/re.html
维基百科 (正则表达式): https://en.wikipedia.org/wiki/Regular_expression
用Javascript替换字符串中符合正则表达式的部分:
var regex_replacer = /test/gi; var test_string = "This is a Test string."; var replace_to_str = "Result"; var result = test_string.replace(regex_replacer,replace_to_str,test_string); console.log(result) ------------------- > "this is a Result string."
用Python替换字符串中符合正则表达式的部分:
import re regex_replacer = re.compile("test", re.IGNORECASE) test_string = "This is a Test string." replace_to = "result" result = regex_replacer.sub(replace_to, test_string) print(result)