On May 29, 2011, at 09:23, jj200...@gmail.com wrote:
> Hi all I would like to find lines like below and replace them with blank lines
> 
> <p class="text">08-06-2011 15:49:25</p>
> <p class="text">08-06-2011 15:54:45</p>
> <p class="text">08-06-2011 15:56:13</p>
> 
> Also is it possible to script so I can replace different lines in the same 
> workflow??
______________________________________________________________________

Hey John,

This one is easy, although GREP usually looks very alien to those unfamiliar 
with it.

Pattern 1 take into account the possibility of single digits in both the date 
and the time, while Pattern 2 assumes a fixed-length date and time.

Pattern 1: <p class="text">\d{1,2}-\d{1,2}-\d{4} \d{1,2}:\d{1,2}:\d{1,2}</p>
Pattern 2: <p class=\"text\">\d{2}-\d{2}-\d{4} \d{2}:\d{2}:\d{2}</p>

\d      == a digit
[0-9]   == although not used here it is a more traditional digit means of 
representing a digit.
{1,2}   == quantifiers: in this case one OR two

Notice that in the script you need to double-up on escape characters - '\' 
becomes '\\'.

------------------------------------------------------------------------------------------------
set grepPattern1 to "<p class=\"text\">\\d{1,2}-\\d{1,2}-\\d{4} 
\\d{1,2}:\\d{1,2}:\\d{1,2}</p>"
set grepPattern2 to "<p class=\"text\">\\d{2}-\\d{2}-\\d{4} 
\\d{2}:\\d{2}:\\d{2}</p>"

tell application "BBEdit"
  try
    tell text of front text window
      replace grepPattern2 using "" options {starting at top:true, search 
mode:grep, case sensitive:false}
      # More replace statements here #

    end tell
  on error errMsg number errNum
    set sep to "=============================="
    set e to sep & return & "Error: " & errMsg & return & sep & return ¬
      & "Error Number: " & errNum & return & sep
    beep
    display dialog e
  end try
end tell
------------------------------------------------------------------------------------------------

You can create multiple replace statements and go to town.

--
Best Regards,
Chris

-- 
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem, 
please email "supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

Reply via email to