Regex only capture first match

I've been googling and looking through recommended question offered by stack overflow. However, I failed to find the answers.

I want to parse a string using regex, example of the string is

Lot: He said: Thou shalt not pass!

I want to capture Lot as a group, and He said: Thou shalt not pass!. However, when I used my (.+): (.+) pattern, it returns

Lot: He said: and Thou shalt not pass!

Is it possible to capture He said: Thou shalt not pass using regex?


You need a non-greedy (or lazy) cardinality for the first group: (.+?): (.+).

More details on, chapter "Laziness Instead of Greediness".

give this a try:



You can use this.

See demo.

The following one works.

([^:]+): (.+)

You should use the flags ig - i = case insensitive, g = don't return after first match and a expression like "(.:) ?(.: .*)".

You can see example here

Need Your Help

Fill form in WebView with Javascript

javascript android android-webview

I'm trying to fill Webforms from a Webview in Android.

When should I recycle a bitmap using LRUCache?

android bitmap android-lru-cache

I'm using an LRUCache to cache bitmaps which are stored on the file system. I built the cache based on the examples here: