Recently I've been working on learning regular expressions. Something about the Java implementation (in jython) I found curious.
Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54)
[OpenJDK Client VM (Sun Microsystems Inc.)] on java1.7.0-internal
Type "help", "copyright", "credits" or "license" for more information.
>>> from java.lang import String
>>> teststring = String('def hello():')
>>> teststring.matches(r'\s*def\s+\w*\(\):$')
True
>>>
[OpenJDK Client VM (Sun Microsystems Inc.)] on java1.7.0-internal
Type "help", "copyright", "credits" or "license" for more information.
>>> from java.lang import String
>>> teststring = String('def hello():')
>>> teststring.matches(r'\s*def\s+\w*\(\):$')
True
>>>
It's just a convenience method. If you are worried about performance, you can of course use Pattern and Matcher directly.
ReplyDelete@Tuure Yeah, that's what I figured. It just seemed a little out of place. I suppose it could be handy though.
ReplyDeleteCarl T.