You can use
/([_*])(?<!(?:1|w).)(?![_*s])(.*?[^_*s])(?=1)([_*])(?!w|3)/g
See the regex demo. Details:
([_*])
- Group 1: _
or *
(?<!(?:1|w).)
- a negative lookbehind: no same char as in Group 1 or any word char and then any char immediately to the left of the current location
(?![_*s])
- a negative lookahead that fails the match if there is _
, *
or whitespace immediately to the right of the current location
(.*?[^_*s])
- Group 2: any zero or more chars other than line break chars, as few as possible, and then a char other than _
, *
or whitespace
(?=1)
- a positive lookahead that requires the same value as in Group 1 to be present immediately to the right of the current location
([_*])
- Group 3: a _
or *
(?!w|3)
- not immediately followed with a word char or same value as in Group 3.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…