Regex matches the string that is the part of an explicit string

Viewed 71

Regex matches the string that is the part of an explicit string.

e.g.

an explict string

hello world!

matches

h
he
...
hello wor
hello worl
hello world!

not matches

a
ah
ha
hallo
hbbbo asrld!
hbbboaasrld!
Thbbboaasrld!

As shown below

/^h(e(l(l(o( (w(o(r(l(d(!?)?)?)?)?)?)?)?)?)?)?)?$/

but it is not convenient for modification and expansion.

Is there a simpler expression?

0 Answers
Related