View Single Post
Old 02-05-2013, 07:36 AM   PM User | #7
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,100
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by xelawho View Post
seems to be OK. The code alert all the same words as the firefox inline spellchecker, which seems good enough. One thing, though - it seems the use of the \w makes the code think that café ends at "f" - any way around that one?
Code:
var x = "So: Théo, I wonder how I can remove (these brackets)... but not the é in café and/ or, \"this\" 'cool' apostrophe, [they're] co-terminous; (I believe!)."

x = x.replace(/\b[^\w\s\u00E0-\u00FC]+\B|\B[^\w\s]+\b/g, "");  // shorter alternative, do not delete accented characters at end of words

alert (x);
If you only want small letter e with acute é the Unicode is \u00E9. I don't think that there are any other accented characters which can appear at the end of a word in (imported) English except perhaps e with grave è which is \u00E8. Obviously many foreign languages use accented characters. In Italian è means is. You might perhaps want to retain La donna è mobile. My code covers all accented lower-case characters and hence all eventualities.

@Old Pedant - my understanding is that we are talking about dictionary words, not proper names. I don't see how any spell checker can check proper names. Some people even mis-spell Philip.
Is there a usually comma in the rendering of Wm. P. Norquist, III ?

@xelawoo - Might I repectfully suggest that you change your thread title to something more indicative of the content - such as "Regex to remove punctuation before/after dictionary words" which would perhaps be more helpful to people using the search feature of this forum.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 02-05-2013 at 10:16 AM..
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
xelawho (02-05-2013)