Lightweight Asynchronous Regex Project
LARP is a library that uses stored regex patterns and returns the pattern matches in a promise. You can also use URLs or filenames as the argument with an options parameter and LARP will parse the source code of the page or text from the file as arguments for the regex marching. More powerful regex magic than a level 15 spell caster!
npm install larp
Import: import * as larp from "larp";
Require: const larp = require("larp");
- Email Addresses
_
email(arg: string, options?: config)
_ Example match: [email protected] - URLS
_
url(arg: string, options?: config)
_ Example match: http://www.example.com - IPv4 Addresses
_
ipv4(arg: string, options?: config)
_ Example match: 127.0.0.1 - HTML src Attribute Values
_
src(arg: string, options?: config)
_ Example match:src="/javascripts/main.js"> - HTML href Attribute Values
_
href(arg: string, options?: config)
_ Example match:href="/examples">
- url
_
{ url: true }
_ Use argument as URL location and URL source will be matched. - file
_
{ file: true }
_ Use argument as file location and file text will be matched.
The string argument specifies the text to be matched.
larp.email("Lorem ipsum [email protected] dolor sit amet.");
=> Promise: [ '[email protected]' ]
larp.url("Lorem ipsum https://www.example.com dolor sit amet.");
=> Promise: [ 'https://www.example.com' ]
larp.ipv4("Lorem ipsum 127.0.0.1 dolor sit amet.");
=> Promise: [ '127.0.0.1' ]
larp.src("<h1>Lorem ipsum</h1><img src="unicorn.png"><h1>dolor sit amet.</h1>");
=> Promise: [ 'unicorn.png' ]
larp.href("<h1>Lorem ipsum</h1><a href="/unicorns.html">Unicorns</a><h1>dolor sit amet.</h1>");
=> Promise: [ '/unicorns.html' ]
The string argument specifies the filename when option { file: true } is provided:
larp.ipv4("sample.txt", { file: true })
=> Promise: [ '127.0.0.1' ]
The string argument specifies the URL location when option { url : true } is provided:
larp.href("http://www.example.com", { url: true })
=> Promise: [ '/stylesheets/style.css', '/examples' ]
- URL Regex from John Gruber