I’m building a project that needs to match a text that is inside : text to match -. For example, if I have this string:
nathanpc/ltweet: Asking a question at #StackOverflow: “Regular Expression To Match a Text Inside : -” – @devs
I want to match Asking a question at #StackOverflow: "Regular Expression To Match a Text Inside : -". Everything that is after the first : and the last -, but what is the correct regular expression to do this?
PS: I’m using Javascript with jQuery
If you’re using Perl-compatible regular expressions, like those found in most languages:
You might not need the slashes, depending on the language. The capture group 1 will get the content you want.
The
.*is a greedy matcher, so it will attempt to match as many characters as possible, up to the last dash in the input.