Find all substrings that fit the mask with asterisks
Yes, there is a more efficient algorithm.  Your algorithm can take exponential time.

You can check whether there exists any match in $O(nm)$ time, where $n$ is the length of text and $m$ is the length of mask, and find all matches in $O(n^2m)$ time.  I'll show two solutions, one using dynamic programming and one using graph search.  You can pick whichever you find easier to understand.

I don't know whether you can do even better.

Dynamic programming

Build an array $A[i,j]$, where $A[i,j]$ is true if some prefix of $\text{text}[i..n]$ matches $\text{mask}[j..m]$.  There's a recursive formula for $A[i,j]$:

$$\begin{align*}
A[i,j] &amp;= \text{True} \qquad &amp;&amp;\text{if } j=m+1\\
A[i,j] &amp;= A[i+1,j+1] \qquad &amp;&amp;\text{if } \text{mask}[j]=\text{text}[i]\\
A[i,j] &amp;= A[i,j+1] \lor \cdots \lor A[n,j+1] \qquad &amp;&amp;\text{if } \text{mask}[j]=*\\
A[i,j] &amp;= \text{False} \qquad &amp;&amp;\text{otherwise}
\end{align*}$$

If you fill this in, in the usual way, you get a $O(nm^2)$ time algorithm.  If you additionally keep track of $B[i,j] = A[i,j+1] \lor \cdots \lor A[n,j+1]$ and fill in entries in the right order, you get a $O(nm)$ time algorithm.

Once you have filled in the matrix, you can find all substrings of text that match: each entry $A[i,1]$ that is true corresponds to one or more substrings of text that match (the substring starts at index $i$ of text).  You can adapt the above algorithm to enumerate all those matching substrings by repeating the above computation once per possible ending place of the match.

There may be even faster methods, using ideas from string matching and/or regular expression matching.

Graph search

Build a directed graph on $nm$ vertices.  Each vertex is of the form $\langle i,j \rangle$, which we think of as corresponding to the problem of checking whether some prefix of $\text{text}[i..n]$ matches $\text{mask}[j..m]$.  Now add the following edges:


Add the edge $\langle i,j \rangle \to \langle i+1,j+1 \rangle$ if mask$[j]$ = text$[i]$.
Add the edge $\langle i,j \rangle \to \langle i,j' \rangle$ if mask$[j] = *$ and $j' &gt; j$.


Finally, mark each vertex $\langle i,m+1 \rangle$ as "accepting".

This is a directed acyclic graph; it has no cycles.  Now, for each $i$, find all accepting vertices that are reachable by some path starting at the vertex $\langle i,1 \rangle$.  If $\langle i',m+1 \rangle$ is reachable from $\langle i,1 \rangle$, that means that the substring text$[i..i'-1]$ matches mask, so you can output this substring.   This computation can be done in $O(nm)$ time per starting point using breadth-first search, for a total of $O(n^2m)$ time.