I am in the process of creating a function to generate a regular expression that can check if a string starts with a specific sequence and contains another specified sequence.
function buildRegExp(startsWith,contains){
return new RegExp( ????? )
}
For instance:
buildRegExp('abc','fg').test('abcdefg')
In this case, the result should be true as the string 'abcdefg' begins with 'abc' and contains 'fg'.
The 'startsWith' and 'contains' strings may overlap, so a simple search for one followed by the other will not suffice for the regular expression.
The following should also result in true:
buildRegExp('abc','bcd').test('abcdefg')
Regular expressions are necessary as I plan to use them in MongoDB queries rather than basic string operations.