7

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

Huangism
  • 15,899
  • 5
  • 47
  • 67
Goenitz
  • 115
  • 1
  • 2
  • 10
  • jQuery is a JavaScript library. How does it relate to C#? – chiccodoro Oct 01 '14 at 12:52
  • sorry wrong title :) – Goenitz Oct 01 '14 at 12:53
  • Search Stackoverflow for "regex greater than less than" – chiccodoro Oct 01 '14 at 12:54
  • you will find http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags, http://stackoverflow.com/questions/17495418/regular-expression-greater-than-and-less-than, and http://stackoverflow.com/questions/21063742/greater-than-and-less-than-symbol-in-regular-expressions, only a few examples. I am sure one of them will answer your question. – chiccodoro Oct 01 '14 at 12:55

3 Answers3

3

You can use regEx | like

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

Fiddle

Y.Puzyrenko
  • 2,118
  • 1
  • 14
  • 23
0

For greater than and less than symbol.

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

For special characters

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

-1

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", ">");

source : http://www.dotnetperls.com/regex-replace

Talha
  • 31
  • 7