On 7/8/07 Patrick James wrote: >On Jul 8, 2007 Dean Matthews wrote: >> How do you set a search and replace grep to replace everything >> between two markers. >> Find >> <div id="footer"> *oldStuff* </div> >> Replace >> <div id="footer"> *newStuff* </div> >Find: >(<div id="footer">)(.|\r)+?(</div>) >Replace: >\1*newStuff*\3
>I'm new to BBEdit and as a question to those who've used it longer I'm >wondering if BBEdit has a wildcard for "any character at all" to replace >(.|\r) ? Here's the best way, opening up another area of regular expressions to master: Use an embedded modifier, in this case 's', which will make the regex engine treat the expression as a single line, i.e., recognizing newlines with '.'. Find: (<div id="footer">)(?s).+?(</div>) Replace: \01*newStuff*\02 Notice that the closing </div> tag now is captured in \02, not \03. This is because the parenthetical pattern (?s), which embeds the modifier as mentioned above, does NOT capture the way parentheses would without the initial '?'. Also, the above FIND expression could have the '(?s) at the start: (?s)(<div id="footer">).+?(</div>) There's more to learn about this -- embedding modifiers in regexes can be quite useful. The BBEdit manual has a good introduction. Finally, it helps to follow the convention of using the zero in single digit capture variables: \01 instead of \1. That way, if the very first character of *newstuff* happened to be a digit, you'd avoid an error. HTH, - Bruce __bruce__van_allen__santa_cruz__ca__ -- ------------------------------------------------------------------ Have a feature request? Not sure the software's working correctly? If so, please send mail to <[EMAIL PROTECTED]>, not to the list. List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml> List archives: <http://www.listsearch.com/BBEditTalk.lasso> To unsubscribe, send mail to: <[EMAIL PROTECTED]>
