正則表達式在線替換工具
關於正則表達式在線替換工具:
這個正則表達式在線替換工具可以幫助您替換字符串中符合您的正則化表達式部分.
鏈接:
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)