bravo
simplified Regular Expression pattern match framework based on RegExp.
Requirements
- Node 0.10+
- Able to write regular expression
Installation
$ npm install bravo
Run
- HTML input:
<head> <title>rockdragon/bravo</title> </head> <body> <div class="wrapper"> <h1>example repository.\r\n</h1> </div>
- JSON-like configuration file:
- {expr} represents either regular expression string, or an array composed of : [{ expr:"", g:1},...]
- {g} represents either the group number of the RegExp; return the all groups if {g} absent; it should not exist when {expr} was an array.
- {sep} represents a separator be used to concatenate result when {expr} was an array.
- {replace} is used for result substitution, it could be either an array or an object whose contains two fields : {a} represent source, and {b} represent destination.
{ "title": { "expr": "<title>([^<]+)</title>", "g": 1 }, "heading": { "expr": "<div class=\"wrapper\">\\s+<h1>([^<]+)</h1>", "g": 1, "replace": [ { "a": "\\\\r\\\\n", "b": "" }, { "a": "example", "b": "awesome" } ] }, "titleAndheading": { "expr": [ { "expr": "<title>([^<]+)</title>", "g": 1 }, { "expr": "<div class=\"wrapper\">\\s+<h1>([^<]+)</h1>", "g": 1 } ], "sep": " - ", "replace": [ { "a": "\\\\r\\\\n", "b": "" }, { "a": "example", "b": "awesome" } ] }}
- Invocation:
//var html = readFromFile();var request = ;var jsonFile = path;var obj = bravo;console});
- Result is a object which had been defined in the JSON file:
License
MIT