For example I have a string like this:
first:second:third"test:test":fourth
I want to count the ‘:’ and later to split every ‘:’ to get the strings.
This is my regex:
/(.*):(.*)/iU
I don’t know if this is the best solution, but it works. There is a different between a ‘.’ and a “[…] : […]” so I need to seperate them. I realized that my regex counts the : but continues when the : is between “.
I tried to solve this with this regex:
/(((.*)[^"]):((.*)[^"]))/iU
I thought this is the right way, but it isn’t. I tried to learn the regex syntax, but I don’t understand this problem.
This regex just means:
search for ‘:’ – every think can be infornt and after it EXCEPT wehen a ” is in front of it AND a ” is after it.
Maybe you can help me.
edit: I use my regex in PHP – maybe this is an important information
How about using
which will give you the result
directly?
This regex splits on a
:only if it’s followed by an even number of quotes. This means that it won’t split on a:inside a string: