TextWrangler variables query...

Hi there,

Please can someone help me with this query.
I’m writing a script to perform a GREP search on some copy using TextWrangler.
The regular expression is working ok and finds the relevant text however what I’d like to do is store
part of the value returned in a variable. This is where I’ve come a little unstuck.

Here’s the regular expression:- (@AG Medium Drop Cap:)([A-Z]*)

As you can see there are two parts to it, it’s the value returned by the second part I want to store in a variable.
If I do a GREP find and replace and put ‘\2’ as the replacement value I can see the right value is being returned.

I’ve had a look at the dictionary and the sample scripts. One of which (shown below) gave me a start but as yet
I’ve not found the right way to get the 2nd ‘subpattern’ value into a variable.

Here’s the script:-

tell application "TextWrangler"
	set matchOptions to {match mode:leaving_one, match pattern:"^.*\\t(<.*>)", match subpattern:"\\1", match subpattern key:use_subpattern}
	set outputOptions to {deleting duplicates:true}
	
	process duplicate lines (text 1 of window 1) ¬
		duplicates options matchOptions ¬
		output options outputOptions
end tell

Please can someone point me in the right direction.

Thanks in advance,

Regards,

Nick

Having looked at a few recorded scripts and the dictionary once again I came up with this:-

tell application "TextWrangler"
	activate
	find "(@AG Medium Drop Cap:)([A-Z]*)" searching in text 1 of text document 1 options {search mode:grep, starting at top:false,
wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false} with selecting match
	
	set SubPatternVal to grep substitution of "\\2"
	display dialog SubPatternVal as text
end tell

The set SubPatternVal to grep substitution of “\2” is what I was looking for.

Thought I’d post it here just incase anyone needs to do this sort of thing, and incase I can’t remember!

Thanks to all who had a look.

Nick