Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 579
Goenitz Avatar asked Oct 01 '14 12:10

Goenitz


People also ask

What does \+ mean in regex?

To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "." ; regex \+ matches "+" ; and regex \( matches "(" .

What does regex 0 * 1 * 0 * 1 * Mean?

Basically (0+1)* mathes any sequence of ones and zeroes. So, in your example (0+1)*1(0+1)* should match any sequence that has 1. It would not match 000 , but it would match 010 , 1 , 111 etc. (0+1) means 0 OR 1.

Can you use wildcard in regex?

In regular expressions, the period ( . , also called "dot") is the wildcard pattern which matches any single character. Combined with the asterisk operator . * it will match any number of any characters.


1 Answers

You can use regEx | like

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

Fiddle

like image 120
Y.Puzyrenko Avatar answered Sep 20 '22 15:09

Y.Puzyrenko