I want to filter out all the words that start out with ==
and also end in ==
, for example ==Hello==
, but I don't want words such as ===Bye===
to be part of such a matching,
I am using the following regex but it doesn't return the results I am looking for: ==(.*?)==
, what mistake am I doing in formulating the regex?
==(.*?)==
still matches ===Bye===
. You need to check specifically that there is no preceding or following =
. You also need to make sure that no =
are captured, so .*
is not going to work. Use [^=]
.
(?<!=)==([^=]*)==(?!=)
Try this:
([^=]|^)==([^=]+)==([^=]|$)
It handles the match occurring at the beginning or end of the given String as well.
(?<!=)==\K[^=]+(?===)(?!===)
在这里看演示。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.