Regular expressions must be greedy?

emdalton - July 29, 2009 - 14:56
Project:Search and Replace Scanner
Version:6.x-1.0
Component:User interface
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

I'd like to get rid of some old server-side includes code in my nodes. So I want to use a search like this:

<!--.+?-->

There are some pages in which if I don't add that final "?" to make the search "lazy," I'll end up deleting real content that needs to stay in the page. But when I try to use this search in Regular Expressions mode, I get this error:

    * user warning: Got error 'repetition-operator operand invalid' from regexp query: SELECT t.body as content, t.nid, n.title FROM node_revisions t INNER JOIN node n ON t.vid = n.vid WHERE n.type = 'curriculum_page' AND t.body REGEXP '<!--.+?-->' in /usr/local/web/lamp/users/wsbe/site/sites/all/modules/scanner/scanner.module on line 801.
    * user warning: Got error 'repetition-operator operand invalid' from regexp query: SELECT t.body as content, t.nid, n.title FROM node_revisions t INNER JOIN node n ON t.vid = n.vid WHERE n.type = 'page' AND t.body REGEXP '<!--.+?-->' in /usr/local/web/lamp/users/wsbe/site/sites/all/modules/scanner/scanner.module on line 801.

No matches are found, though I get 64 returns if I leave out the "?" and let the regexp be greedy. Any suggestions?

#1

emdalton - July 29, 2009 - 21:39

Workaround: I searched on <!--[^<>]+--> instead. But if scanner doesn't support lazy matching, probably this should be documented.

#2

aasarava - July 31, 2009 - 15:52

Thanks for the heads up and the workaround. I'll look into this to see if lazy matching is truly disallowed, or if there's some change I can make to the code to get this working.

 
 

Drupal is a registered trademark of Dries Buytaert.