I will say that your (?:^|\.|\?|\!) seemed to have mostly worked. Surprised me.
Yes, I forgot a | in this expression. ^ means the beginning of the line when it is outside of a character class.
So this is a non-capturing group that will be either the beginning of a line (or the string), a full-stop, etc..
But, no, I'm not testing it as thoroughly as you are.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
Last edited by AndrewGSW; 01-31-2013 at 10:49 PM..
I notice you using [^.] instead of [^\.\?\!] so I changed that
@Old Pedant - yes, the ! and ? weren't mentioned until recently
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
(the rule is not that it must begin with a capital letter, but that if there is no capital letter preceding the keyword, it captures the string from the start)
(the rule is not that it must begin with a capital letter, but that if there is no capital letter preceding the keyword, it captures the string from the start)
And what about a period that is *NOT* followed by a capital letter?
aardvarks whistle. dogs jump when they are happy
Given your rule as stated here, that would return the *entire* string.
Is that truly what you want?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
but all my sentences begin with capital letters (sic.) and end with a smile
Just for completeness (for anyone reading) to embed a string in a regex requires use of the RegExp constructor:
Code:
var re = new RegExp("^\\/" + resource + "\\/\\d+$");
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
Last edited by AndrewGSW; 01-31-2013 at 11:49 PM..
(the rule is not that it must begin with a capital letter, but that if there is no capital letter preceding the keyword, it captures the string from the start)
thanks everybody!
Don't these versions drop the first letter?
Added: I think I would account for zero or more spaces at the beginning as well:
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
Last edited by AndrewGSW; 01-31-2013 at 11:58 PM..
And what about a period that is *NOT* followed by a capital letter?
aardvarks whistle. dogs jump when they are happy
Given your rule as stated here, that would return the *entire* string.
Is that truly what you want?
Yes. This is to do spellchecks on content editable divs on a website for professional writers. If they're starting their sentences with lower case letters they have bigger problems than a few extra characters in their output.
maybe a little detail will help. The spellchecker scans the text nodes, so if the innerHTML is
Code:
I had a <b>great</b> day
it will scan 3 chunks:
1) I had a
2) great
3) day
Which is kind of meaningless there, but there could be an entire paragraph without formatting and so you just want to show a snippet. A sentence would be ideal, but by the time the spellchecker gets to the text it's all broken up into text nodes. So instead of piecing it back together, there are the four rules (rule 3 revised halfway through this thread):
- Start capturing from the closest word before the variable word that starts with a capital/uppercase.
- If there is no word that starts with a capital before the variable word, start capturing from the start of the string.
- Equally, if the part of the string after the variable word contains a full stop, exclamation mark or question mark, finish capturing at the punctuation.
- If not, capture until the end of the string.
Well, I gave you my answer, using 4 regexps. Which I see no reason can't be combined into one. And then one more regexp eliminates not only any preceding [.?!] but also trims the string on the left side of any spaces.
Unless you are a fanatic about doing it all with a single regexp, I don't see what is wrong with that. What difference does it make if it's 1 regexp or 2 or 5?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
Last edited by AndrewGSW; 02-01-2013 at 01:34 AM..