You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
4.3 KiB

4 years ago
  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. > POSIX character classes for creating regular expressions.
  3. ## Install
  4. Install with [npm](https://www.npmjs.com/):
  5. ```sh
  6. $ npm install --save posix-character-classes
  7. ```
  8. Install with [yarn](https://yarnpkg.com):
  9. ```sh
  10. $ yarn add posix-character-classes
  11. ```
  12. ## Usage
  13. ```js
  14. var posix = require('posix-character-classes');
  15. console.log(posix.alpha);
  16. //=> 'A-Za-z'
  17. ```
  18. ## POSIX Character classes
  19. 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>:
  20. | **POSIX class** | **Equivalent to** | **Matches** |
  21. | --- | --- | --- |
  22. | `[:alnum:]` | `[A-Za-z0-9]` | digits, uppercase and lowercase letters |
  23. | `[:alpha:]` | `[A-Za-z]` | upper- and lowercase letters |
  24. | `[:ascii:]` | `[\x00-\x7F]` | ASCII characters |
  25. | `[:blank:]` | `[ \t]` | space and TAB characters only |
  26. | `[:cntrl:]` | `[\x00-\x1F\x7F]` | Control characters |
  27. | `[:digit:]` | `[0-9]` | digits |
  28. | `[:graph:]` | `[^[:cntrl:]]` | graphic characters (all characters which have graphic representation) |
  29. | `[:lower:]` | `[a-z]` | lowercase letters |
  30. | `[:print:]` | `[[:graph] ]` | graphic characters and space |
  31. | `[:punct:]` | ``[-!"#$%&'()*+,./:;<=>?@[]^_`{ | }~]`` | all punctuation characters (all graphic characters except letters and digits) |
  32. | `[:space:]` | `[ \t\n\r\f\v]` | all blank (whitespace) characters, including spaces, tabs, new lines, carriage returns, form feeds, and vertical tabs |
  33. | `[:upper:]` | `[A-Z]` | uppercase letters |
  34. | `[:word:]` | `[A-Za-z0-9_]` | word characters |
  35. | `[:xdigit:]` | `[0-9A-Fa-f]` | hexadecimal digits |
  36. ## Examples
  37. * `a[[:digit:]]b` matches `a0b`, `a1b`, ..., `a9b`.
  38. * `a[:digit:]b` is invalid, character classes must be enclosed in brackets
  39. * `[[:digit:]abc]` matches any digit, as well as `a`, `b`, and `c`.
  40. * `[abc[:digit:]]` is the same as the previous, matching any digit, as well as `a`, `b`, and `c`
  41. * `[^ABZ[:lower:]]` matches any character except lowercase letters, `A`, `B`, and `Z`.
  42. ## About
  43. ### Contributing
  44. Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
  45. ### Building docs
  46. _(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.)_
  47. To generate the readme, run the following command:
  48. ```sh
  49. $ npm install -g verbose/verb#dev verb-generate-readme && verb
  50. ```
  51. ### Running tests
  52. 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:
  53. ```sh
  54. $ npm install && npm test
  55. ```
  56. ### Author
  57. **Jon Schlinkert**
  58. * [github/jonschlinkert](https://github.com/jonschlinkert)
  59. * [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
  60. ### License
  61. Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
  62. Released under the [MIT License](LICENSE).
  63. ***
  64. _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.5.0, on April 20, 2017._
  65. <hr class="footnotes-sep">
  66. <section class="footnotes">
  67. <ol class="footnotes-list">
  68. <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>
  69. </li>
  70. </ol>
  71. </section>