javascript 检测字符串中大于“>”和小于“<”的正则表达式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26141732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Regex that detects greater than ">" and less than "<" in a string
提问by Goenitz
I need a regular expression that replaces the greater than and less than symbol on a string
我需要一个正则表达式来替换字符串上的大于和小于符号
i already tried
我已经试过了
var regEx = "s/</</g;s/>/>/g"
var testString = "<test>"
alert(testString.replace(regEx,"*"))
My first time to use it please go easy on me :) Thanks
我第一次使用它,请放轻松:)谢谢
采纳答案by Y.Puzyrenko
回答by Aravind G
For greater than and less than symbol.
用于大于和小于符号。
var string = '<><>';
string = string.replace(/[\<\>]/g,'*');
alert(string);
var string = '<><>';
string = string.replace(/[\<\>]/g,'*');
alert(string);
For special characters
对于特殊字符
var string = '<><>';
string = string.replace(/[&\/\\#,+()$~%.'":*?<>{}]/g,'_');
alert(string);
var string = '<><>';
string = string.replace(/[&\/\\#,+()$~%.'":*?<>{}]/g,'_');
alert(string);
回答by Talha
Insert the regular expression in the code before class
在类之前的代码中插入正则表达式
using System.Text.RegularExpressions;
below is the code for string replace using regex
下面是使用正则表达式进行字符串替换的代码
string input = "Dot > Not Perls";
// Use Regex.Replace to replace the pattern in the input.
string output = Regex.Replace(input, "some string", ">");