In a sentence similar to:
Lorem ipsum + dolor ++ sit amet.
I would like to match +dolor , but not ++sit . I can do this with lookbehind, but since JavaScript does not support it, I'm struggling to build a template for it.
So far I have tried:
(?:\+(.+?))(?=[\s\.!\!]) - but it matches both words (?:\+{1}(.+?))(?=[\s\.!\!]) - the same here - both words are matched
and, to my surprise, it looks like this:
(?=\s)(?:\+(.+?))(?=[\s\.!\!])
nothing matches. I thought I could trick him and use \s or later also ^ in front of the + sign, but it doesn't seem to work.
EDIT - reference information:
This is not necessarily part of the question, but sometimes itโs good to know that all this is good in order to clarify some of your questions / comments with a short explanation:
- any word in any order can be marked with either a
+ or ++ - each word and its marking will be replaced by
<span> later - cases like lorem + ipsum are considered invalid because it would be like splitting a word (ro + om) or spelling two words together as one word (myroom), so it should be fixed in any case (the pattern may match this but this is not a mistake), however it should at least correspond to normal cases, as in the example above
- I use lookahead, for example
(?=[\s\.!\!]) So that I can match words in any language not only \w characters
source share