News for hackers. Stuff that matters.
Re:Ask HN: So, I need regular expressions... by Piskvorrr on Monday May 27, 2013 @04:55AM (#5773962)
See, that's exactly what the maxim is about: "I know, I'll use regular expressions, [because regular expressions are the universal text manipulation tool]." Now you indeed have two problems, because regex is not an appropriate tool here.

You are absolutely not looking for a regular expression (as the grammatical rules and their exceptions are not all that easy to reimplement in regexp syntax), you are looking for a dictionary (a set of key-value pairs, i.e. "American zpelling" => "British spelling" ;)). Then iterate through each word in the document, see if it's a dictionary key, if so, replace with the relevant value. No regex needed.

Re:Ask HN: So, I need regular expressions... by seanccox on Monday May 27, 2013 @08:17AM (#5774364)
That's very helpful. Since I am just starting out, I often find myself trying to use the wrong tool for a job, because I simply don't know what the hell I'm doing. I can use a dictionary as you describe to correct the spelling issues, then I suppose regex can be used on certain formatting problems (if need be)?

Since I am just getting started, can you tell me how I would go about building such a dictionary? For instance, should I create a text file with the word pairs (American, British), or two different files for each?

Thanks for the direction, and apologies if these questions seem foolish. As I indicated, I made something that works, but is slow and buggy. Getting direction on how to move forward really is a big help. Cheers.

Re:Ask HN: So, I need regular expressions... by Piskvorrr on Monday May 27, 2013 @08:29AM (#5774401)
Probably keep the pairs together. Not sure what Applescript uses for hashmaps, but you probably want to load your dictionary into a hashmap or something like that, and lookup in that (much faster than on-disk access).
Re:Ask HN: So, I need regular expressions... by jaachan on Monday May 27, 2013 @05:01AM (#5773975)
Unless you also want to fix things like spacing and whatnot. Some formatting rules can be pretty complex. But I agree that a dictionary would be an essential part to the spellcheck part.