Skip to content

Commit 4e19054

Browse files
committed
iterative matching regex on code blocks
1 parent 7857918 commit 4e19054

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

bot.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ function logMessage(message, edit)
112112
// return an array of all the code blocks contained in a string
113113
function getCodeBlocks(string)
114114
{
115-
// how to make it only collect whats in ( and ) ?
116-
// so we don't have to explicitely chop off the code block delimiters?
117115
const regex = /\`\`\`([a-z]*[\s\S]*?)\`\`\`/g;
118-
return (string.match(regex) || []).map(s => s.slice(3, -3));
116+
const result = [];
117+
var matches;
118+
while((matches = regex.exec(string)) !== null) result.push(matches[1]);
119+
return result;
119120
}
120121

121122
// return an array of links of some domain in a string

0 commit comments

Comments
 (0)