+ 1
[JavaScript] Matching anything in between colons?
So I need to match and return any value that's in between 2 colons. So "n3rfb3fib:eh:rjkbib" would return "eh". How can I do this?
4 Réponses
+ 6
var str = "n3rfb3fib:eh:rjkbib";
alert( str.match(/:(.*):/)[1] ); // eh
+ 2
var match = str.match(/[;|:].*?[;|:]/);
0
is it important to have a opening and closing colon?
0
If you're asking if it matters whether or not to match the colons themselves, no, it's not important.
If you're asking if the value needs to be between 2 colons, yes, it's important.
(Only read further if you want to know the exact issue)
I'll tell you why I need this if it helps.
Take this error for example:
ReferenceError: i is not defined
at Events (<anonymous>:5:55)
I need to match the 5 (Aka the line number) and display it. The line numbers seem to be between colons, so i'm trying to match that and display it.
The error I want displayed should be something like this:
ReferenceError: i is not defined (Line 5)