Regex: Lookahead Assertion And Lookbehind Assertion

Positive Lookahead Assertion => (?=pattern)

Match re in regular word

"a regular expression"
/re(?=gular)/

Negative Lookahead Assertion => (?!pattern)

Match re not in regular word

"a regular expression"
/re(?!gular)/

Positive Lookbehind Assertion => (?<=pattern)

Match re inside word but not beginning of the word.

"regex represents regular expression"
/(?<=\w)re/

Negative Lookbehind Assertion => (?<!pattern)

Match re the beginning of the word but not inside word.

"regex represents regular expression"
/(?<!\w)re/

Reference:

Ruby Regex Doc

正则表达式的先行断言(lookahead)和后行断言(lookbehind)