I want to get the input String splitted by a colon. For example, a:int. I can use [^:]* to get the a and int.
However, I don’t want the String to be split by any combination which includes colon, such as A:=3:command. What I want are the A:=3 and command but not A, =3, command.
Could someone tell me how to write the regular expression?
I’m going to assume, pending an edit by the OP, that the only colons that should appear in a split are those followed by simple ASCII letters or numbers. The solution can easily be generalized.
Here is a concrete example in JavaScript:
The result is
The split function says “split on colons that are followed by spaces or word characters (ASCII letters or numbers or underscores)”.
Other languages have more powerful forms of lookaround (in particular negative lookarounds), but the basic idea is to construct a regex where the split value is a colon in a particular context.
ADDENDUM
Another example:
produces: