On Sep 30, 2016, at 16:53, jgill <[email protected] 
<mailto:[email protected]>> wrote:
> I need to extract the date from <h3>September 30th</h3> in a HTML document
> 
> I can search using - set theMonth to find "<h3>\\s*(.*?)\\s*</h3> 
> <smb://s*</h3>>" searching in text 1 of text document "index.html" options 
> {search mode:grep} with selecting match
> 
> How can I access the \1 reference inside the brackets in Applescript?


Hey Joe,

As far as I know you can't in find operations, although you can in replace 
operations.

Find with selecting found string is a poor way to do a replace – it's slow and 
cumbersome – although it can be the only way to accomplish jobs under some 
circumstances.

The better way is to use replace (if it works for that job):

-------------------------------------------------------------------------------------------
tell application "BBEdit"
   replace "MATCH" using "REPLACE" options {search mode:grep, case 
sensitive:false, starting at top:true}
end tell
-------------------------------------------------------------------------------------------

Otherwise you may have to do something like this:

-------------------------------------------------------------------------------------------
tell application "BBEdit"
   tell front document
      set foundTextRecord to find "<h3>\\s*(.*?)\\s*</h3> <smb://s*</h3>>" 
options {search mode:grep, starting at top:true} with selecting match
      set foundText to found text of foundTextRecord
      set parsedText to replace "<h3>\\s*(.*?)\\s*</h3> <smb://s*</h3>>" 
searchingString foundText using "\\1 <smb://1>" options {search mode:grep, case 
sensitive:false, starting at top:true}
   end tell
end tell
-------------------------------------------------------------------------------------------

And that's why I generally prefer to use the Satimage.osax for find and 
find/replace operations.

-------------------------------------------------------------------------------------------
# Requires the Satimage.osax
# http://www.satimage.fr/software/en/downloads/downloads_companion_osaxen.html 
<http://www.satimage.fr/software/en/downloads/downloads_companion_osaxen.html>
-------------------------------------------------------------------------------------------

set _text to bbeditFrontWinText()

try
   set parsedText to find text "<h3>\\s*(.*?)\\s*</h3> <smb://s*</h3>>" in 
_text using "\\1 <smb://1>" with regexp and string result without all 
occurrences
on error
   set parsedText to false
end try

if parsedText ≠ false then
   # DO SOMETHING
end if

-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
on bbeditFrontWinText()
   tell application "BBEdit"
      tell front document to its text
   end tell
end bbeditFrontWinText
-------------------------------------------------------------------------------------------

Although I will often turn to a Perl, awk, or sed text filter when it's 
efficient to do so.

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or would like to report a problem, please email
"[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/bbedit.

Reply via email to