1
|
# posix-character-classes [![NPM version](https://img.shields.io/npm/v/posix-character-classes.svg?style=flat)](https://www.npmjs.com/package/posix-character-classes) [![NPM monthly downloads](https://img.shields.io/npm/dm/posix-character-classes.svg?style=flat)](https://npmjs.org/package/posix-character-classes) [![NPM total downloads](https://img.shields.io/npm/dt/posix-character-classes.svg?style=flat)](https://npmjs.org/package/posix-character-classes) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/posix-character-classes.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/posix-character-classes)
|
2
|
|
3
|
> POSIX character classes for creating regular expressions.
|
4
|
|
5
|
## Install
|
6
|
|
7
|
Install with [npm](https://www.npmjs.com/):
|
8
|
|
9
|
```sh
|
10
|
$ npm install --save posix-character-classes
|
11
|
```
|
12
|
|
13
|
Install with [yarn](https://yarnpkg.com):
|
14
|
|
15
|
```sh
|
16
|
$ yarn add posix-character-classes
|
17
|
```
|
18
|
|
19
|
## Usage
|
20
|
|
21
|
```js
|
22
|
var posix = require('posix-character-classes');
|
23
|
console.log(posix.alpha);
|
24
|
//=> 'A-Za-z'
|
25
|
```
|
26
|
|
27
|
## POSIX Character classes
|
28
|
|
29
|
The POSIX standard supports the following classes or categories of charactersh (note that classes must be defined within brackets)<sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup>:
|
30
|
|
31
|
| **POSIX class** | **Equivalent to** | **Matches** |
|
32
|
| --- | --- | --- |
|
33
|
| `[:alnum:]` | `[A-Za-z0-9]` | digits, uppercase and lowercase letters |
|
34
|
| `[:alpha:]` | `[A-Za-z]` | upper- and lowercase letters |
|
35
|
| `[:ascii:]` | `[\x00-\x7F]` | ASCII characters |
|
36
|
| `[:blank:]` | `[ \t]` | space and TAB characters only |
|
37
|
| `[:cntrl:]` | `[\x00-\x1F\x7F]` | Control characters |
|
38
|
| `[:digit:]` | `[0-9]` | digits |
|
39
|
| `[:graph:]` | `[^[:cntrl:]]` | graphic characters (all characters which have graphic representation) |
|
40
|
| `[:lower:]` | `[a-z]` | lowercase letters |
|
41
|
| `[:print:]` | `[[:graph] ]` | graphic characters and space |
|
42
|
| `[:punct:]` | ``[-!"#$%&'()*+,./:;<=>?@[]^_`{ | }~]`` | all punctuation characters (all graphic characters except letters and digits) |
|
43
|
| `[:space:]` | `[ \t\n\r\f\v]` | all blank (whitespace) characters, including spaces, tabs, new lines, carriage returns, form feeds, and vertical tabs |
|
44
|
| `[:upper:]` | `[A-Z]` | uppercase letters |
|
45
|
| `[:word:]` | `[A-Za-z0-9_]` | word characters |
|
46
|
| `[:xdigit:]` | `[0-9A-Fa-f]` | hexadecimal digits |
|
47
|
|
48
|
## Examples
|
49
|
|
50
|
* `a[[:digit:]]b` matches `a0b`, `a1b`, ..., `a9b`.
|
51
|
* `a[:digit:]b` is invalid, character classes must be enclosed in brackets
|
52
|
* `[[:digit:]abc]` matches any digit, as well as `a`, `b`, and `c`.
|
53
|
* `[abc[:digit:]]` is the same as the previous, matching any digit, as well as `a`, `b`, and `c`
|
54
|
* `[^ABZ[:lower:]]` matches any character except lowercase letters, `A`, `B`, and `Z`.
|
55
|
|
56
|
## About
|
57
|
|
58
|
### Contributing
|
59
|
|
60
|
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
|
61
|
|
62
|
### Building docs
|
63
|
|
64
|
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
|
65
|
|
66
|
To generate the readme, run the following command:
|
67
|
|
68
|
```sh
|
69
|
$ npm install -g verbose/verb#dev verb-generate-readme && verb
|
70
|
```
|
71
|
|
72
|
### Running tests
|
73
|
|
74
|
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
|
75
|
|
76
|
```sh
|
77
|
$ npm install && npm test
|
78
|
```
|
79
|
|
80
|
### Author
|
81
|
|
82
|
**Jon Schlinkert**
|
83
|
|
84
|
* [github/jonschlinkert](https://github.com/jonschlinkert)
|
85
|
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
|
86
|
|
87
|
### License
|
88
|
|
89
|
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
|
90
|
Released under the [MIT License](LICENSE).
|
91
|
|
92
|
***
|
93
|
|
94
|
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.5.0, on April 20, 2017._
|
95
|
|
96
|
<hr class="footnotes-sep">
|
97
|
<section class="footnotes">
|
98
|
<ol class="footnotes-list">
|
99
|
<li id="fn1" class="footnote-item">table and examples are based on the WikiBooks page for [Regular Expressions/POSIX Basic Regular Expressions](https://en.wikibooks.org/wiki/Regular_Expressions/POSIX_Basic_Regular_Expressions), which is available under the [Creative Commons Attribution-ShareAlike License](https://creativecommons.org/licenses/by-sa/3.0/). <a href="#fnref1" class="footnote-backref">↩</a>
|
100
|
|
101
|
</li>
|
102
|
</ol>
|
103
|
</section>
|