Switching the Internet Proxy on/off

I had the problem, that I need to use a proxy at work and no proxy at home. The only thing I did, was to switch the proxy on in the morning and off in the evening, you get used to it, but it is not nice. I found some scripts on the Internet, but what was not working, is that after enabling or disabling the proxy by script, it seems that the open browser was not notified about the change of the proxy setting. I had to close and reopen the browser after each change.

When I searched on the Internet, I found some people, that had the same problem, but normally without an answer how to solve it. The only answer I found was here on StackOverflow. This lead to a powershell script on GitHub , that has a function that uses WinINet and InternetSetOption() to set the options “INTERNET_OPTION_SETTINGS_CHANGED” and “INTERNET_OPTION_REFRESH”.

This did not solve my issue directly, but I set me on the correct trail, I found another option “INTERNET_OPTION_PROXY_SETTINGS_CHANGED” that did the trick for me.

The result is a powershell script that you can find here on GitHub

Useful regex resources

Today I want to post a list of regex resources that have been useful for me. In the first time I haven’t read a regex book, I found all my knowledge on-line, and there is plenty of regex information out there.

On-line resources

As example, because those languages provide good documentation and because I know them best, here the regex docs for Perl and C#. Especially the Perl tutorials can be recommended also to regex learners of other languages, just ignore the, by your language not supported, advanced parts.


  • perlrequick, Perl regular expressions quick start, a tutorial that gives a basic regex understanding.
  • perlretut, Perl regular expressions tutorial. A really extensive tutorial going into all details of Perl regexes.
  • perlre, the Perl regex module documentation.


Online Regex Tester

  • Regexr, my favourite one. Based on Flex, supports lookahead and fixed length lookbehind. Has also a regex community library and explain regex constructs. It is also possible to create permanent links to solutions.
  • Rubular, based on Ruby, allows also to create permanent links.
  • Regular Expression Analyzer, give it a regex and it will analyze it
  • Refiddle, you can choose the regex engine (JavaScript, Ruby, .NET)


You do know Quantifiers. Really?


Everybody knows the Quantifiers + and *. Most will also know ?. But do you know that they are only shortcuts for convenience? No?

The real quantifier in regular expressions is {m,n} where m is a number that defines the minimum amount to match and n is the number that defines the upper bound. The upper bound can be omitted, that means there is no upper bound.

It can also be only a number between the curly brackets like this: {4}. That means match exactly 4.

So, now back to the quantifiers we all know +, * and ?. What are they now?

? makes something optional. Means match it 0 or 1 time. So the long version is {0,1}
* matches something 0 or more times, that is then {0,}
+ matches at least once, that is in the long version {1,}

Matching Behaviour

Greedy versus Lazy

The default matching behaviour of regex quantifiers is greedy, they match as much as possible. E.g. the regex /a.*a/ would match from the first a to the last a.

Our test string here shall be ababababababa

/a.*a/ would match ababababababa in our test string.

but sometimes this is too much and one would only match till the next a. So what to do? There exists a modifier that changes the matching behaviour of a quantifier, this is the question mark ? ! Wait, what? Yes, if you see something like this /a.*?a/ it does not make the * optional (would make no sense, eh), it modifies the behaviour of the *

So /a.*?a/ would match only ababababababa in our test string.

Read more about repetition on regular-expressions.info


Some regex engines have an additional modifier for quantifiers. That modifier is the + and changes the matching behaviour to be “possessive”, means what that quantifier has matched is not released anymore. There is no backtracking within that quantifier. That is sometimes useful to make a regex fail faster.

/a.++/ would match ababababababa in our test string.

/a.++a/ would not match abababababa. What!? Why not?

Because a.*+ matched the first “a” (obviously) and the rest matched the string till the end. At the end the regex still requires to match an “a”, so a normal quantifier would give back (backtrack) the last  “a”, so that the regex can find the last “a” in the string. But the possessive quantifier will not give back any character that it has matched, and therefore the regex can’t find a match and fails.

If you know atomic groups, then it is more easy for you. A possessive quantifier is the same as when you would place a atomic group around that single quantifier. So /a.++a/ is the same as /a(?>.+)a/ .

As usual a link to Jan Goyvaerts great page regular-expressions.info, he has also an article about Possessive Quantifiers where he explains the matching behaviour and the background more detailed.


There is more about quantifiers than only ?+*. If needed, the amount of  required repetitions and the matching behaviour can be adjusted to the particular needs. Just keep in mind there is more about quantifiers and remember that, when your regex does not match what you expect it to.

I would be happy to read your comments, if you haven’t understood a single word (and of course also, when you learned something and liked it, or when something in between happened)

Do you write readable regexes?

 Why not?

Imagine you have a regex to validate a password


Thats not too complicated, but the readability could be better. The solution here is the option x or IgnorePatternWhitespace.

Most regular expression flavours allow you to use the option x, this is an important option everybody should know, who want to write longer patterns. The option x is doing two things:

  1. Allows to use whitespace to make the pattern more readable
  2. Allows the usage of comments inside the pattern

The whitespace used then inside the pattern does not belong to the pattern itself, it is only to improve the readability.  But that means also that if you want to match e.g. a space you have to escape it using a or use the whitespace class \s.

Example in C#

Regex password = new Regex(@"
        ^ # Match the start of the string
        (?=.*\p{Lu}) # Positive lookahead assertion, is true when there is an uppercase letter
        (?=.*\P{L}) # Positive lookahead assertion, is true when there is a non-letter
        \S{8,} # At least 8 non whitespace characters
        $ # Match the end of the string
    ", RegexOptions.IgnorePatternWhitespace);

Looks a lot better, what do you think?

That way its much clearer what this regex is doing and together with meaningful comments, even a regex novice will see quite quick what this part of the code is doing.

This useful feature is available in the most important languages like .NET, Java, Perl, PCRE, Python, Ruby. it is not supported by e.g. ECMA (JavaScript) and POSIX BRE/POSIX ERE (the PHP ereg functions are using  POSIX ERE, the preg functions are using PCRE).

So, in future, hopefully everyone is going to write readable regexes. You have now seen that it is not a feature of regular expressions to be unreadable, it is as always  the programmer how writes unreadable code.

For more details about this option you can have a look at  regular-expressions.info

How to test your regular expression

Of course, the ultimate tool is RegexBuddy by Jan Goyvaerts. I personally don’t have it at the moment, but I surely need to get it soon. It supports various languages, gives you detailed explanation on each part, you can step through the matching process …

But if you use regex not often and do only small ones, you should be fine with free online regular expression testers. And it is important that you test your regex, extract use cases from your real data and add also test data that you don’t want to match!

Online regex testers are a great help while developing a regular expression. As long as you do not want to use features they don’t support, they visualize your match and show you the content of the capturing groups instantly.

Critical features, you should test in your real language, are mainly lookbehind assertions and Unicode  features like Unicode properties.

My favourites are

Regexr is based on ActionScript 3, that means it implements regex after the ECMA-262 standard.  See regular-expressions.info for more info. (I am not sure if the standard has changed or Regexr has changed, because Regexr supports simple look behind assertions, but ECMA-262 does not).

Matches are highlighted and the content of the capturing groups is shown when the mouse hovers over the match, it also allows to test replacements and allows to create permalinks to your tested regex (to share it easily on SO ;))

Rubular is based on Ruby.   See regular-expressions.info for more info. Matches are highlighted and the matches and the content of the according capturing groups are shown in a list. The regex is processed on a server, therefore the result is not shown instantly but quite quick the most of the time. It allows also to create permalinks to your tested regex

Other online testers are (I use them not often, but try them to find your personal favorite)

And at last, this is not tool for testing, you can give it a regex and it tells you what this is doing: