Regex can get very confusing very fast. One problem beginners tend to have is something called 'greedy regex'. For example, say you want to parse some bb code, let's say a url tag, like so:
[ URL=
http://google.com/]Go to google![/URL ]
You may try a regex like this:
#\
\].+\[/URL\]#i (the i at the end is to indicate case insensitive regex)
This expression seems like it will work fine, but the problem is that .+ part. That .+ part will chomp all the way through the entire string that you give it until it reaches the last in the code, thus why it is called 'greedy'. This can be prevented in two ways:
.+? <-- very simple and effective.
[^\[] <-- Searches for everything that isn't a '[' until it reaches one.
Anyway, that's all. Also keep in mind that the regex i provided above is simplified for ease-of-reading and that it is vulnerable to xss attacks. You should always make sure that the urls provided start with http:// or ftp://
Anyway, have fun learning regex! ^_^
¯\_(ツ)_/¯ It works on my machine...