Allow matching substrings instead of patterns #1035
Labels
a-2d
Relates to the 2d package
b-enhancement
New feature or request
c-accepted
The issue is ready to be worked on
Description
Currently, the
Code.findAllRanges
method does not match an exact substring in aCode
object. Instead, it unnecessarily creates aRegExp
object. If thefindAllCodeRanges
function can take aRegExp
object as an argument, why should it have to convert astring
toRegExp
?Solution
I could not find any existing function that matched a substring in the docs, so I am suggesting a quick change to remove some code from the
findAllCodeRanges
function inpackages/2d/src/lib/code/CodeRange.ts
.This means we can use
code().findFirstRange('n * (n + 1) / 2')
instead of typing out so many backslashes like this:code().findFirstRange('n \\* \\(n \\+ 1\\) \\/ 2')
. It is probably better practice to use aRegExp
constructor instead of implicitly converting astring
into aRegExp
.The text was updated successfully, but these errors were encountered: