[Tutor] Regular Expresions instances

spir denis.spir at free.fr
Wed Apr 29 09:57:56 CEST 2009


Le Tue, 28 Apr 2009 22:51:09 +0000 (GMT),
Emilio Casbas <ecasbasj at yahoo.es> s'exprima ainsi:

> 
> Hi,
> 
> following the example from
> http://docs.python.org/3.0/howto/regex.html
> 
> If I execute the following code on the python shell (3.1a1):
> 
> >>> import re
> >>> p = re.compile('ab*')
> >>> p
> 
> I get the msg:
> <_sre.SRE_Pattern object at 0x013A3440>

So do I using python 1.5.2. Slightly better than the version below (at least they tell you you got a %?$£^pattern).

> instead of the msg from the example:
> <re.RegexObject instance at 80b4150>

I guess this pure question of vocabulary. At a remote point in time the regex package has changed, especially the name of the type for patterns -- and the doc did not follow.

> Why I get an SRE_Patterns object instead of a RegexObject instance?

Actually, there are loads of lexical issues in the world of programming ;-)
What you need to know is, IMO (comments welcome):
(1) A pure string is used to describe how source text should be structured.
(2) This string is then used to construct an object able to check that.

There is a high confusion with terms like 'format', 'pattern', 'rule', 'expression'; and 'regex' itself is used for every other notion, including the *language* used to write strings in (1).
I personly use 'pattern' for objects (2) -- but it's far to be a norm. When parsing with regexes, then 'RegexObject' can be a synonym for 'pattern'.
On the other hand, you will find all other words, even 'pattern', used in sense (1).

> Regards
> Emilio

Denis
------
la vita e estrany


More information about the Tutor mailing list