Jython: Regular expression error: sre_constants.error ( nothing to repeat )

Asked by T G

Using Sikulix 1.10 I am attempting to compile a regular expression. I run into the following error when I attempt the code below.

Code:

regex_search = re.compile(r'Foo: (.*)? Bar: (.*)? Title: (.*)')

Error:

[error] script [ regex_error_hndl ] stopped with error in line 29
[error] sre_constants.error ( nothing to repeat )
[error] --- Traceback --- error source first line: module ( function ) statement 190: re ( compile ) File "C:\Users\Public\Documents\Sikulix\sikulix.jar\Lib\re.py", line 242, in _compile
[error] --- Traceback --- end --------------

1.1.0(2015-10-05_17:07)/Windows6.1/Java8(64)1.8.0_74-b02

1.1.0(2015-10-05_17:07)/Windows6.1/Java8(64)1.8.0_74-b02

Further comments:

Related post that I found regarding this error (http://stackoverflow.com/questions/3675144/regex-error-nothing-to-repeat)

I believe the issue is with the ".*" portion of the regular expression. I have been unable to figure out a way to adjust my expression to avoid these meta characters. Do you have any suggestions? Is there a way to use a more recent version of python with sikulix? I am fairly new to the world of scripting and programming, these are the sorts of problem that thoroughly stump me. Sikulix has been a fantastic tool to learn on.

Is there any additional info needed to assess this problem?

Any help would be greatly appreciated

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

--- I believe the issue is with the ".*"
apparently not, because this is accepted:

regex_search = re.compile(r'Foo: (.*?) Bar: (.*?) Title: (.*?)')

... so you have to put the ? directly after the *, which makes sense, since it modifies the behavior of * (not-greedy), but is not defined for a group (...)

I agree, that the error message is not really helpful ;-)

BTW: you are using the latest possible Python language interpreter with SikuliX: Jython 2.7.0

Can you help with this problem?

Provide an answer of your own, or ask T G for more information if necessary.

To post a message you must log in.