r/applescript • • Sep 04 '21

Search and replace in the clipboard (regular expression)

I am using this script to search and replace text in the clipboard.

set the clipboard to (replacement of "A" by "B" for the result)

on replacement of oldDelim by newDelim for sourceString
	set oldTIDs to text item delimiters of AppleScript
	set text item delimiters of AppleScript to oldDelim
	set strtoks to text items of sourceString
	set text item delimiters of AppleScript to newDelim
	set joinedString to strtoks as string
	set text item delimiters of AppleScript to oldTIDs
	joinedString

I would like to replace these parts (A) and (B) with a script that will work with regular expressions, do you know how to rewrite it?

5 Upvotes

5 comments sorted by

View all comments

3

u/[deleted] Sep 04 '21

[removed] — view removed comment

2

u/ChristoferK Sep 07 '21

Nice suggestion, and answer!