Change return to empty string on no single match
| @@ -2177,14 +2177,15 @@ export function initDefaultSlashCommands() { | ||
| 2177 | 2177 | if (!pattern) { |
| 2178 | 2178 | throw new Error('Argument of \'pattern=\' cannot be empty'); |
| 2179 | 2179 | } |
| 2180 | 2180 | letconst re = regexFromString(pattern.toString()); |
| 2181 | 2181 | if (!re) { |
| 2182 | 2182 | throw new Error('The value of \'pattern\' argument is not a valid regular expression.'); |
| 2183 | 2183 | } |
| 2184 | 2184 | if (re.flags.includes('g')) { |
| 2185 | 2185 | return JSON.stringify([...text.toString().matchAll(re)]); |
| 2186 | 2186 | } else { |
| 2187 | 2187 | returnconst JSON.stringify(match = text.toString().match(re)); |
| 2188 | + return match ? JSON.stringify(match) : ''; | |
| 2188 | 2189 | } |
| 2189 | 2190 | }), |
| 2190 | 2191 | returns: 'group array for each match', |
| @@ -2205,7 +2206,7 @@ export function initDefaultSlashCommands() { | ||
| 2205 | 2206 | <div> |
| 2206 | 2207 | Returns an array of groups (with the first group being the full match). If the regex contains the global flag (i.e. <code>/g</code>), |
| 2207 | 2208 | multiple nested arrays are returned for each match. If the regex is global, returns <code>[]</code> if no matches are found, |
| 2208 | 2209 | otherwise it returns nullan empty string. |
| 2209 | 2210 | </div> |
| 2210 | 2211 | <div> |
| 2211 | 2212 | <strong>Example:</strong> |
| @@ -2213,7 +2214,7 @@ export function initDefaultSlashCommands() { | ||
| 2213 | 2214 | <pre><code class="language-stscript">/match pattern="green" {{var::x}} | /echo |/# [ "green" ] ||</code></pre> |
| 2214 | 2215 | <pre><code class="language-stscript">/match pattern="color_(\\w+)" {{var::x}} | /echo |/# [ "color_green", "green" ] ||</code></pre> |
| 2215 | 2216 | <pre><code class="language-stscript">/match pattern="/color_(\\w+)/g" {{var::x}} | /echo |/# [ [ "color_green", "green" ], [ "color_blue", "blue" ] ] ||</code></pre> |
| 2216 | 2217 | <pre><code class="language-stscript">/match pattern="orange" {{var::x}} | /echo |/# null ||</code></pre> |
| 2217 | 2218 | <pre><code class="language-stscript">/match pattern="/orange/g" {{var::x}} | /echo |/# [] ||</code></pre> |
| 2218 | 2219 | </div> |
| 2219 | 2220 | `, |