samedi 24 septembre 2022

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

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?

Aucun commentaire:

Enregistrer un commentaire