get the static part of a RegExp

I want to get the static part of a RegExp string, which 100% guaranteed to not have a regex-specific characters, except the grouping parentheses ().

for instance, this regex /path/config-(.+)/.js/ has a static part /path/config- until the character ‘.’

use cases:

I want to search for all matched entries inside a folder that have too many files and subfolders.

so, it is a bit faster to start searching from the basic path /path that doesn’t needed to be matched against, instead of starting from the root directory.