To match a string with pattern like:
-TEXT-someMore-String
To get -TEXT-
, I came to know that this works:
/-(.+?)-/ // -TEXT-
As of what I know, ?
makes preceding token as optional as in:
colou?r
matches both colour
and color
I initially put in regex to get -TEXT-
part like this:
/-(.+)-/
But it gave -TEXT-someMore-
.
How does adding ?
stops regex to get the -TEXT-
part correctly? Since it used to make preceding token optional not stopping at certain point like in above example ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…