Reputation: 18127
I'm trying to match ABC
from *ABC*
, but not from **ABC**
.
I've this so far;
/[^\*]{1}\*([^\*]+)\*[^\*]+/
The strings to match can be any of the following.
ABC **Don't match this** DEF
ABC *Match this* DEF
*Match this*
**Don't match this**
Upvotes: 1
Views: 145
Reputation:
Your on the right track.
Without assertions: /(?:^|[^*])\*[^*]+*(?:[^*]|$)/
(use aioobe's regex with assertions, or any combination with/without).
Upvotes: 1
Reputation: 6084
if the string starts and ends with "*" you could use this:
/^*([^*]+)*$/
Upvotes: 0
Reputation: 421040
You could use negative look-behind, negative look-ahead. That is
(?<!\*)\*ABC\*(?!\*)
Which reads out as
*ABC*
not preceeded by*
, and not succeeded by*
.
Upvotes: 6