11// Extractor: regexmatch
2+ // [[extractor targetinput="ans2" type="regexmatch" regex="^f\\(x\\)\\s*=\\s*" /]]
3+ // Note the scaped backslashes. Searches for a trimmed line beginning 'f(x) = ' where
4+ // there can be any amount of whitespace around the equals. Returns 'f(x) = expr'.
25// Scans blocks (bottom-up) for the last code_inline or asciimath_block line
36// matching entry.regex, then sets answerEl.value to the matched string.
47export default function regexmatch ( raw , answerEl , blocks , entry ) {
@@ -13,7 +16,7 @@ export default function regexmatch(raw, answerEl, blocks, entry) {
1316 if ( block . type === 'code_inline' ) {
1417 const trimmed = block . raw . trim ( ) ;
1518 if ( pattern . test ( trimmed ) ) {
16- answerEl . value = trimmed . match ( pattern ) [ 0 ] ;
19+ answerEl . value = trimmed ;
1720 answerEl . dispatchEvent ( new Event ( 'change' ) ) ;
1821 return ;
1922 }
@@ -23,7 +26,7 @@ export default function regexmatch(raw, answerEl, blocks, entry) {
2326 for ( let j = lines . length - 1 ; j >= 0 ; j -- ) {
2427 const trimmed = lines [ j ] . trim ( ) ;
2528 if ( pattern . test ( trimmed ) ) {
26- answerEl . value = trimmed . match ( pattern ) [ 0 ] ;
29+ answerEl . value = trimmed ;
2730 answerEl . dispatchEvent ( new Event ( 'change' ) ) ;
2831 return ;
2932 }
@@ -39,7 +42,7 @@ export default function regexmatch(raw, answerEl, blocks, entry) {
3942 for ( const line of lines ) {
4043 const trimmed = line . trim ( ) ;
4144 if ( pattern . test ( trimmed ) ) {
42- answerEl . value = trimmed . match ( pattern ) [ 0 ] ;
45+ answerEl . value = trimmed ;
4346 answerEl . dispatchEvent ( new Event ( 'change' ) ) ;
4447 return ;
4548 }
0 commit comments