Sets

Introduction

A character set is a collection of characters that can match any single character that is a member of the set.

Form

Sets are delimited by "[" and "]" and can contain literals, character ranges and character classes.

Use

Example

The pattern "[abc]" matches "a", "b", or "c".

var pattern = /[abc]/; var string = "abcdabc"; document.writeln(string.match(pattern));

On running the above code, the following output is obtained.

Example

The pattern "[^abc]" matches any character other than "a", "b", or "c".

var pattern = /[^abc]/; var string = "abcdabc"; document.writeln(string.match(pattern));

On running the above code, the following output is obtained.