Reputation: 21
Hey guys i am trying to find a pattern in a string let's say this is my string
Hello World :this is what i am trying to detect:
i am looking for a regex that matches anything that comes between
:"STRING":
i googled a bit and found some results, but nothing seems to be working. I successfully matched :test:
but more than one word and it's breaking
this is the best answer i got
^[:]\\w+|(?<=\\s)[@#]\\w+
Upvotes: 1
Views: 432
Reputation: 772
([:][A-Za-z0-9]+[:])
You can put more character in this range or directly use \s
Upvotes: 0
Reputation: 10476
You can use that :
:(.*?):
Explanation:
:
looks for the first :.*?
lazily matches everything until the next ::
ends the matchingUPDATE:
If you want go beyond : and look for any special of the following group then you can try this:
[:#@]([^:#@]*?)[:#@]
Upvotes: 3
Reputation: 727077
The trick to matching between characters X
is to match "everything except X
" for the body of the message:
:[^:]*:
The expression means literally this:
:
[^:]*
:
Upvotes: 2