Please enable JavaScript to use regex101
/
^
r
e
g
e
x
[
\
-
_
]
?
1
0
1
$
/
i
Reg
ular
Ex
pressions
101
Upgrade to Pro
Enterprise
Regular Expression
/
^((key1|key2|key3):\w+|\b(?!(?2)\b)\w+)(?:\h+(?1))*$
/
gm
Input 1
1
New
aaa bbb ccc aaa bbb key1:aaa ccc ddd aaa bbb key2:aaa key1:bbb aaa bbb key1 ccc => INVALID (key1 not follows the rule key:value) aaa bbb key1:xxx key2: => INVALID (key2 not follows the rule key:value) aaa bbb key1: xxx ccc => INVALID (not accept space after colon) aaa bbb key1 :xxx ccc => INVALID (not accept space before colon) aaa bbb aakey1 => VALID (aakey1 is not the keyword) aaa bbb key1aa => VALID (key1aa is not the keyword) aaa bbb xxx:yyy zzz => VALID (Do not accept any key:value that the key is not in the keyword list)
Substitution
aaa bbb ccc aaa bbb key1:aaa ccc ddd aaa bbb key2:aaa key1:bbb aaa bbb key1 ccc => INVALID (key1 not follows the rule key:value) aaa bbb key1:xxx key2: => INVALID (key2 not follows the rule key:value) aaa bbb key1: xxx ccc => INVALID (not accept space after colon) aaa bbb key1 :xxx ccc => INVALID (not accept space before colon) aaa bbb aakey1 => VALID (aakey1 is not the keyword) aaa bbb key1aa => VALID (key1aa is not the keyword) aaa bbb xxx:yyy zzz => VALID (Do not accept any key:value that the key is not in the keyword list)