Regex检测到大于“>"并且小于“0”<"在字符串中

Regex that detects greater than ">" and less than "<" in a string

本文关键字:quot lt 字符串 小于 gt 检测 Regex 大于      更新时间:2023-09-26

我需要一个正则表达式来替换字符串上的大于和小于符号

我已经试过了

var regEx = "s/</</g;s/>/>/g"
var testString = "<test>"
alert(testString.replace(regEx,"*"))

我第一次使用它,请对我宽容一点:)感谢

您可以像一样使用regEx |

var regEx = /<|>/g;
var testString = "<test>"
alert(testString.replace(regEx,"*"))

Fiddle

对于大于和小于符号。

var string = '<><>';
string = string.replace(/['<'>]/g,'*');
alert(string);

对于特殊字符

var string = '<><>';
string = string.replace(/[&'/''#,+()$~%.'":*?<>{}]/g,'_');
alert(string);

在类之前的代码中插入正则表达式

using System.Text.RegularExpressions;

下面是使用regex 替换字符串的代码

string input = "Dot > Not Perls";
// Use Regex.Replace to replace the pattern in the input.
string output = Regex.Replace(input, "some string", ">");

来源:http://www.dotnetperls.com/regex-replace