Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sophiebits/match-at
Relocatable regular expressions.
https://github.com/sophiebits/match-at
Last synced: 2 months ago
JSON representation
Relocatable regular expressions.
- Host: GitHub
- URL: https://github.com/sophiebits/match-at
- Owner: sophiebits
- License: mit
- Created: 2015-03-26T21:15:32.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-09-06T02:02:13.000Z (over 7 years ago)
- Last Synced: 2024-04-25T02:41:43.110Z (9 months ago)
- Language: JavaScript
- Size: 27.3 KB
- Stars: 8
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# match-at [![Build Status](https://travis-ci.org/spicyj/match-at.svg?branch=master)](https://travis-ci.org/spicyj/match-at)
## Introduction
Like `String.prototype.match` if it only checked the regex at the given index instead of searching the entire string.
```js
matchAt(/world/, 'hello world', 6); // ['world']
matchAt(/world/, 'hello world', 0); // null
```Almost like `'hello world'.slice(i).match(/^world/)` except the resulting match object's `.index` property corresponds to the original string, and it doesn't actually slice the string. Most engines optimize taking a substring so this probably isn't particularly valuable in practice, but it was an entertaining exercise and could be useful if you reminisce about these semantics.
## License
MIT.