View Single Post
Old 04-05-2014, 03:29 AM   #1
Skeeve
Zealot
Skeeve ought to be getting tired of karma fortunes by now.Skeeve ought to be getting tired of karma fortunes by now.Skeeve ought to be getting tired of karma fortunes by now.Skeeve ought to be getting tired of karma fortunes by now.Skeeve ought to be getting tired of karma fortunes by now.Skeeve ought to be getting tired of karma fortunes by now.Skeeve ought to be getting tired of karma fortunes by now.Skeeve ought to be getting tired of karma fortunes by now.Skeeve ought to be getting tired of karma fortunes by now.Skeeve ought to be getting tired of karma fortunes by now.Skeeve ought to be getting tired of karma fortunes by now.
 
Skeeve's Avatar
 
Posts: 142
Karma: 669192
Join Date: Nov 2013
Device: Kindle 4.1.1 no touch
An introduction to regular expressions - a small advise

Hi!

I just had a look at the sticky thread mentioned in the subject and I think it should be quite useful for starters.

I just like to add one small advise:

Quote:
For ignoring case, the flag is "i", thus you include "(?i)" in your expression. Thus,
Code:
Code:
test(?i)
would match "Test", "tEst", "TEst" and any case variation you could think of.
I'm not a python programmer, but I'm using perl for almost 20 years now and I'd like to draw your attention to the fact that (?flag) in perl is taking effect from the place where you put the flag up to the end of the surrounding group. So that regexp would only match "test" but not "Test" or "TEST".

Well, you may object, in python it's different and in fact http://www.pythonregex.com/ suggests so.

Nevertheless I'd strongly advise to not put the flags anywhere in the regexp, but just at the beginning. This will make things much easier and additionally, follows the python regular expression documentation which states:

Quote:
Note that the (?x) flag changes how the expression is parsed. It should be used first in the expression string, or after one or more whitespace characters. If there are non-whitespace characters before the flag, the results are undefined.
So instead of
Code:
test(?i)
better use
Code:
(?i)test
Skeeve is offline   Reply With Quote