How to ignore punctuation in text? [Quark: Deleting words]

Hello all. Thanks for the great info on this site. I am working on a script for automatic text formatting in Quark. Using example scripts and documentation, it is going pretty good so far. The problem I am having is that I need to delete the text “(AP)” How do I get Applescript to ignore the parenthesis in the quotes and search for it as text? Thanks!

Hi,

if the parentheses are always the first and last character of the string,
one possible solution is:

set a to text 2 thru -2 of "(AP)" --> "AP"

if not, check it additionally

set theText to "(AP)"
if theText begins with "(" and theText ends with ")" then
	set a to text 2 thru -2 of "(AP)" --> "AP"
end if

I am using this:

tell paragraph 2
set a to text 2 thru -2 of “(AP)”
delete (every word where it is a)
end tell

and it is deleting AP and leaving the parenthesis. I want to delete this —> (AP)

Thank you for helping me.

word does not include punctuation. It’s usually not a very good way of doing things.

I don’t have Quark, but you can try something like this: (You need to make sure that paragraph 2 is properly referenced.)

set ASTID to AppleScript's text item delimiters
try
	set AppleScript's text item delimiters to {"(AP)"}
	set temp to text items of paragraph 2
	
	set AppleScript's text item delimiters to {""}
	set paragraph 2 to "" & temp
end try
set AppleScript's text item delimiters to ASTID

It was “word” that was the problem. Using “text” fixed it. I thought the () characters were the issue. Thank you!

tell paragraph 4
delete (every text where it is " (AP)")
end tell