moss
moss

Reputation: 3

What is this user-input regex checking for? /^[^<">]*$/

This regex is used to check some user input:

/^[^<">]*$/

What is it checking for?

Upvotes: 0

Views: 206

Answers (8)

Colin O&#39;Dell
Colin O&#39;Dell

Reputation: 8647

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.

Upvotes: 0

Jeff Meatball Yang
Jeff Meatball Yang

Reputation: 39057

/^[^<">]*$/

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

It will match anything else.

Upvotes: 1

gnarf
gnarf

Reputation: 106392

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.

Upvotes: 2

LorenVS
LorenVS

Reputation: 12867

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

Upvotes: -2

Nick Dandoulakis
Nick Dandoulakis

Reputation: 43130

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

Upvotes: 0

retracile
retracile

Reputation: 12339

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

Upvotes: 1

Michael Myers
Michael Myers

Reputation: 192015

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 <>".

Upvotes: 7

Jo&#227;o Silva
Jo&#227;o Silva

Reputation: 91349

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

Upvotes: 10

Related Questions