-1

Is it possible to perform the following match?

^do something$

.. where matches are possible for a partially typed 'something'.

For example:

^do s$
^do so$
^do som$
^do some$
^do somet$
^do someth$
^do somethi$
^do somethin$
^do something$

Is it possible to do this with regex without having to string a bunch of logical ORs?

Zhro
  • 2,546
  • 2
  • 29
  • 39

2 Answers2

0

There is no need to use regex :

function isMatch(input)
{
   var key="do something";
   return key.startsWith(input) && input.length <= key.length;
}
nAviD
  • 2,784
  • 1
  • 33
  • 54
0

If you just want to match partially "something", you could do:

\^do\s+((?:something|somethin|somethi|someth|somet|some|som|so|s))\$

Here is the demo.

Quinn
  • 4,394
  • 2
  • 21
  • 19