regex - Positive lookahead not working as expected -


i have following regex positive lookahead:

/black(?=hand)[ s]/ 

i want match blackhands or blackhand. however, doesn't match anything. testing on regex101.

what doing wrong?

lookahead not consume string being searched. means [ s] trying match space or s following black. however, lookahead says hand must follow black, regular expression can never match anything.

to match either blackhands or blackhand while using lookahead, move [ s] within lookahead: black(?=hand[ s]). alternatively, don't use lookahead @ all: blackhand[ s].


Comments