Skip to content

Commit 66aa9b5

Browse files
committed
Update docs
1 parent 0f52a62 commit 66aa9b5

File tree

2 files changed

+49
-16
lines changed

2 files changed

+49
-16
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,11 @@ const XRegExp = require('xregexp');
257257
## Contribution guide
258258

259259
1. Fork the repository and clone the forked version locally.
260-
1. Ensure you have the `typescript` module installed globally.
261-
1. Run `npm install`.
262-
1. Ensure all tests pass with `npm t`.
263-
1. Add tests for new functionality or that fail from the bug not fixed.
264-
1. Implement functionality or bug fix to pass the test.
260+
2. Ensure you have the `typescript` module installed globally.
261+
3. Run `npm install`.
262+
4. Ensure all tests pass with `npm test`.
263+
5. Add tests for new functionality or that fail from the bug not fixed.
264+
6. Implement functionality or bug fix to pass the test.
265265

266266
## Credits
267267

docs/api/index.html

+44-11
Original file line numberDiff line numberDiff line change
@@ -754,8 +754,8 @@ <h2 id="matchRecursive"><code>XRegExp.matchRecursive(<span class="plain">str, le
754754
<p><strong>Requires the XRegExp.matchRecursive addon</strong>, which is bundled in <code>xregexp-all.js</code>.</p>
755755

756756
<p>Returns an array of match strings between outermost left and right delimiters, or an array of
757-
objects with detailed match parts and position data. An error is thrown if delimiters are
758-
unbalanced within the data.</p>
757+
objects with detailed match parts and position data. By default, an error is thrown if
758+
delimiters are unbalanced within the subject string.</p>
759759

760760
<table cellspacing="0" class="api">
761761
<tbody>
@@ -775,7 +775,33 @@ <h2 id="matchRecursive"><code>XRegExp.matchRecursive(<span class="plain">str, le
775775
Any combination of XRegExp flags, used for the left and right delimiters.
776776
</li>
777777
<li>[<code>options</code>] {<code>Object</code>}<br/>
778-
Lets you specify <code>valueNames</code> and <code>escapeChar</code> options.
778+
Options object with optional properties:
779+
<ul>
780+
<li><code>valueNames</code> {<code>Array</code>} Providing <code>valueNames</code> changes the return value from an array of
781+
matched strings to an array of objects that provide the value and start/end positions
782+
for the matched strings as well as the matched delimiters and unmatched string segments.
783+
To use this extended information mode, provide an array of 4 strings that name the parts
784+
to be returned:
785+
<ol>
786+
<li>String segments outside of (before, between, and after) matches.</li>
787+
<li>Matched outermost left delimiters.</li>
788+
<li>Matched text between the outermost left and right delimiters.</li>
789+
<li>Matched outermost right delimiters.</li>
790+
</ol>
791+
Taken together, these parts include the entire subject string if used with flag <code>g</code>.<br/>
792+
Use <code>null</code> for any of these values to omit unneeded parts from the returned results.
793+
</li>
794+
<li><code>escapeChar</code> {<code>String</code>} Single char used to escape delimiters within the subject string.</li>
795+
<li><code>unbalanced</code> {<code>String</code>} Handling mode for unbalanced delimiters. Options are:
796+
<ul>
797+
<li><code>'error'</code> - throw (default)</li>
798+
<li><code>'skip'</code> - unbalanced delimiters are treated as part of the text between delimiters, and
799+
searches continue at the end of the unbalanced delimiter.</li>
800+
<li><code>'skip-lazy'</code> - unbalanced delimiters are treated as part of the text between delimiters,
801+
and searches continue one character after the start of the unbalanced delimiter.</li>
802+
</ul>
803+
</li>
804+
</ul>
779805
</li>
780806
</ul>
781807
</td>
@@ -794,13 +820,13 @@ <h2 id="matchRecursive"><code>XRegExp.matchRecursive(<span class="plain">str, le
794820

795821
<h3>Example</h3>
796822
<pre class="sh_javascript">// Basic usage
797-
let str = '(t((e))s)t()(ing)';
798-
XRegExp.matchRecursive(str, '\\(', '\\)', 'g');
823+
const str1 = '(t((e))s)t()(ing)';
824+
XRegExp.matchRecursive(str1, '\\(', '\\)', 'g');
799825
// -> ['t((e))s', '', 'ing']
800826

801827
// Extended information mode with valueNames
802-
str = 'Here is &lt;div> &lt;div>an&lt;/div>&lt;/div> example';
803-
XRegExp.matchRecursive(str, '&lt;div\\s*>', '&lt;/div>', 'gi', {
828+
const str2 = 'Here is &lt;div> &lt;div>an&lt;/div>&lt;/div> example';
829+
XRegExp.matchRecursive(str2, '&lt;div\\s*>', '&lt;/div>', 'gi', {
804830
valueNames: ['between', 'left', 'match', 'right']
805831
});
806832
/* -> [
@@ -812,8 +838,8 @@ <h3>Example</h3>
812838
] */
813839

814840
// Omitting unneeded parts with null valueNames, and using escapeChar
815-
str = '...{1}.\\{{function(x,y){return {y:x}}}';
816-
XRegExp.matchRecursive(str, '{', '}', 'g', {
841+
const str3 = '...{1}.\\{{function(x,y){return {y:x}}}';
842+
XRegExp.matchRecursive(str3, '{', '}', 'g', {
817843
valueNames: ['literal', null, 'value', null],
818844
escapeChar: '\\'
819845
});
@@ -825,9 +851,16 @@ <h3>Example</h3>
825851
] */
826852

827853
// Sticky mode via flag y
828-
str = '&lt;1>&lt;&lt;&lt;2>>>&lt;3>4&lt;5>';
829-
XRegExp.matchRecursive(str, '&lt;', '>', 'gy');
854+
const str4 = '&lt;1>&lt;&lt;&lt;2>>>&lt;3>4&lt;5>';
855+
XRegExp.matchRecursive(str4, '&lt;', '>', 'gy');
830856
// -> ['1', '&lt;&lt;2>>', '3']
857+
858+
// Skipping unbalanced delimiters instead of erroring
859+
const str5 = 'Here is &lt;div> &lt;div>an&lt;/div> unbalanced example';
860+
XRegExp.matchRecursive(str5, '&lt;div\\s*>', '&lt;/div>', 'gi', {
861+
unbalanced: 'skip'
862+
});
863+
// -> ['an']
831864
</pre>
832865

833866

0 commit comments

Comments
 (0)