https://github.com/bjarneo/among
Find the substring / element between the $start and $end argument.
https://github.com/bjarneo/among
regex substring-search
Last synced: 8 months ago
JSON representation
Find the substring / element between the $start and $end argument.
- Host: GitHub
- URL: https://github.com/bjarneo/among
- Owner: bjarneo
- License: mit
- Created: 2017-05-17T16:01:01.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-17T16:06:33.000Z (about 9 years ago)
- Last Synced: 2025-01-08T02:22:37.971Z (over 1 year ago)
- Topics: regex, substring-search
- Language: JavaScript
- Size: 6.84 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
among
--

Find the substring / element between the $start and $end argument.
Developers often need to find a string between two elements. This package will simplify that task by abstract away the regex part.
Usage
--
```bash
$ npm i --save among
```
```js
const among = require('among');
const str = 'The [quick] [brown] {{fox}} $jumps$ over the [lazy] {{dog}}';
let find = among('{{', '}}');
console.log(find(str));
find = among('[', ']', true);
console.log(find(str));
console.log(among('$', '$')(str));
```
Result:
```
[ 'fox', 'dog' ]
[ '[quick]', '[brown]', '[lazy]' ]
[ 'jumps' ]
```
Api
--
```
const find = among(string $start, string $end [, boolean $preserved]);
find(string $str)
```
* $start is the first string to match
* $end is the last string to match
* $preserved is if the $start and $end strings should be preserved(optional)
* $str the input string to search for elements
Tests
--
```bash
$ npm test
```
Contribution
--
Contributions are appreciated.
License
--
MIT-licensed. See LICENSE.