[PyKDE] eric: do regular expressions work?

Detlev Offenbach detlev at die-offenbachs.de
Sun Nov 7 13:37:47 GMT 2004


Am Montag, 1. November 2004 03:29 schrieb Parzival Herzog:
> I have wrestled a  lot with the eric3 search & replace regexps. Today
> I was completely stumped by what seems to me to be a very simple task:
> to find the text "time" or "localtime".
>
> With the text:
> --------------
> def today(time=localtime):
>     ''' datetime for midnight, today '''
>     tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday,
> tm_isdst = time()
>     return date(tm_year, tm_mon, tm_mday)
> --------------
>
> Searching for "time", and "localtime", (separately, and not a regular
> expression) finds these.
>
> Searching for "time|localtime" (regular expression) finds nothing.
> The eric regular expression syntax is not documented, so I
> tried:
>
> "(time)|(localtime)" (maybe alternation has higher precedence than
> concatenation)
>
> "\(time\)|\(localtime\)" (maybe meta-parentheses need to be escaped)
>
> "time)\|localtime" (maybe alternation needs to be escaped)
>
> They all  failed to find "time" or "localtime" in the above text.
>
> Is the regexp search broken, or is the syntax even weirder than what I
> tried?
>
> Could you provide a summary of the regexp syntax (including valid
> references for replacement text) used in eric?
>
> Could you make the syntax more "normal", i.e. don't escape
> parentheses for grouping, or more like (er exactly like!) the KDE text
> editor component?

The regular expressions in the search and replace dialog are the ones defined 
by QScintilla as they go directly (unaltered) to the QScintilla widget 
component. The following is an excerpt from the  scintilla documentation.

-----------------------------------------------
In a regular expression, special characters interpreted are:

.	Matches any character

\(	This marks the start of a region for tagging a match.

\)	This marks the end of a tagged region.

\n	Where n is 1 through 9 refers to the first through ninth tagged region when 				
replacing. For example, if the search string was Fred\([1-9]\)XXX and the 
replace string was Sam\1YYY, when applied to Fred2XXX this would generate 
Sam2YYY.

\<	This matches the start of a word using Scintilla's definitions of words.

\>	This matches the end of a word using Scintilla's definition of words.

\x	This allows you to use a character x that would otherwise have a special 
meaning. For example, \[ would be interpreted as [ and not as the start of a 
character set.

[...]	This indicates a set of characters, for example, [abc] means any of the 
characters a, b or c. You can also use ranges, for example [a-z] for any 
lower case character.

[^...]	The complement of the characters in the set. For example, [^A-Za-z] 
means any character except an alphabetic character.

^	This matches the start of a line (unless used inside a set, see above).

$	This matches the end of a line.

*	This matches 0 or more times. For example, Sa*m matches Sm, Sam, Saam, Saaam 
and so on.

+	This matches 1 or more times. For example, Sa+m matches Sam, Saam, Saaam and 
so on.
-------------------------------------------------

I hope this helps a little bit.

Detlev
-- 
Detlev Offenbach
detlev at die-offenbachs.de




More information about the PyQt mailing list