Re:Ask HN: So, I need regular expressions...
by jaachan on Monday May 27, 2013 @05:00AM
(#5773972)
I've got no experience in Applescript, so my advice might not be worth much.
That said, since you have three problems, solve them each on their own:
* First, do something really simple with Regex, to make sure you can use them in your app (say, in JS, it'd be something like
alert('test'.replace(/st/, 'ssst'));
Then you know the regex engine itself is working.
* Next, you need to figure out how to change text in the document. Not sure if you have already got this covered.
* Then it's a matter of applying the two. Note that regex functions return the changed string, rather than change the string itself. In the example listed on the documentation it does:
set s to change "^[ ]+" into "" in s with regexp
i.e. first change the string (change "^[ ]+" into "" in s with regexp) then store it (set s to <expr>
That said, since you have three problems, solve them each on their own: * First, do something really simple with Regex, to make sure you can use them in your app (say, in JS, it'd be something like
Then you know the regex engine itself is working. * Next, you need to figure out how to change text in the document. Not sure if you have already got this covered. * Then it's a matter of applying the two. Note that regex functions return the changed string, rather than change the string itself. In the example listed on the documentation it does: i.e. first change the string (change "^[ ]+" into "" in s with regexp) then store it (set s to <expr>All in all pretty vague advice I guess.