tags:

views:

117

answers:

8

This regex is used to check some user input:

/^[^<">]*$/

What is it checking for?

+10  A: 

It's checking for a line (possibly empty) that doesn't contain <, > or ".

JG
emphasis on *or*
Michael Haren
+1. In multiline mode this is what it'll do. If it's not in multiline mode it'll search the entire string to ensure it doesn't contain any of these characters.
Steve Wortham
+7  A: 

It's checking for double quotes (") and angle brackets (<>).

/^[^<">]*$/

/^ means the start of the string.
[^<">] means not <, ", or >.
* means zero or more of the previous expression.
$/ means the end of the string.

So it's checking whether the input consists of zero or more characters, none of which are <>".

Michael Myers
+1  A: 

That none of these characters appear on the line: < > "

retracile
A: 

Any string that doesn't contain <"> characters.

Nick D
A: 

This is probably a simple regex being used to check for an xml element with an attribute.

LorenVS
+2  A: 

It ensures that the input contains no < " or > characters.

^ at the beginning matches the literal beginning of the string.

[^<">]* matches 0 or more characters that ARENT one of the three: <">.

$ at the end matches the literal end of the string.

gnarf
+1  A: 
/^[^<">]*$/

To be clear: it does not match any string that contains <, >, or ".

It will match anything else.

Jeff Meatball Yang
A: 

Matching a string against this RegEx will return FALSE if any double-quotes or brackets exist in the string. If none exist, or the string is empty, it will return TRUE.

Colin O'Dell