
but I'm rather out of practice. Fire away and I'll see what I can do.
( ,
Sun 20 Apr 2008, 5:42,
archived)

When I get paid more than them.*
* not very often!
( ,
Sun 20 Apr 2008, 5:49,
archived)
* not very often!

shit will go fine, because frankly i'm fucking amazing, but i'm a little lazy...
( ,
Sun 20 Apr 2008, 5:51,
archived)

otherwise we would still be hunter gathering and not have invented the wheel.
And I love my wheels!
/Stephen Hawking blog
( ,
Sun 20 Apr 2008, 6:09,
archived)
And I love my wheels!
/Stephen Hawking blog

All I need to do is replace a period with a period and a space("." with ". "), but ONLY if the initial period is followed by any non-whitespace character other than another period. So:
"Yes.No" would become "Yes. No"
"Yes...No" would become "Yes... No"
"Yes. No" would not be changed.
( ,
Sun 20 Apr 2008, 5:49,
archived)
"Yes.No" would become "Yes. No"
"Yes...No" would become "Yes... No"
"Yes. No" would not be changed.

then replace " "(two spaces) with " "(one)
( ,
Sun 20 Apr 2008, 5:52,
archived)

unless of course you want to be able to have double spaces elsewhere, then you're fucked
( ,
Sun 20 Apr 2008, 5:54,
archived)

I need to be able to leave the text pretty much untouched, because that will matter to the people entering it. But I can't allow single periods in the middle of lines of text, it's too risky in terms of form security in the context it will be used.
( ,
Sun 20 Apr 2008, 5:58,
archived)

Tried posting multiple spaces here?
( ,
Sun 20 Apr 2008, 6:00,
archived)

So ... would become . . .
Also, I don't want to run replace twice on the string when I can (hopefully) write a regex that will do the job in one pass. I know it's possible, I just haven't been able to get it right.
( ,
Sun 20 Apr 2008, 5:55,
archived)
Also, I don't want to run replace twice on the string when I can (hopefully) write a regex that will do the job in one pass. I know it's possible, I just haven't been able to get it right.

but is trying to just figure an expression that will handle it in a single pass rather than multiple
( ,
Sun 20 Apr 2008, 6:04,
archived)

I'm using them already on the string previous to this, but I need the very specific replacement routine I've outlined above.
( ,
Sun 20 Apr 2008, 5:53,
archived)

find .
read next char
if not space
replace with space + char
or
find .
read next char
if not space
insert space in string at relevant point (the position of which you should be able to drag from your loopish searchy algodoodah)
( ,
Sun 20 Apr 2008, 5:57,
archived)
read next char
if not space
replace with space + char
or
find .
read next char
if not space
insert space in string at relevant point (the position of which you should be able to drag from your loopish searchy algodoodah)

And the most efficient way to do that is with JavaScript's replace function and a smart regular expression.
I got very close, I guess I'll just have to persevere until I get the last part right.
( ,
Sun 20 Apr 2008, 6:00,
archived)
I got very close, I guess I'll just have to persevere until I get the last part right.

Damn my being out of practice. Any chance you could post what you have, I might be able to adapt it a little
( ,
Sun 20 Apr 2008, 6:02,
archived)

newString = oldString.replace(/\.+[^\.\s]/g, ". ");
Here's the result of this:
"Yes no.Yes no. Yes no. Yes no..."
becomes
"Yes no. es no. Yes no. Yes no..."
It's doing everything I need (which is to say, it's not adding spaces where it shouldn't), with the exception that it replaces the Y after the period.
( ,
Sun 20 Apr 2008, 6:11,
archived)
Here's the result of this:
"Yes no.Yes no. Yes no. Yes no..."
becomes
"Yes no. es no. Yes no. Yes no..."
It's doing everything I need (which is to say, it's not adding spaces where it shouldn't), with the exception that it replaces the Y after the period.

newString = oldString.replace(/\.(?!\.|\s)/g, ". ");
( ,
Sun 20 Apr 2008, 6:46,
archived)

Fucking yeah, that's perfect.
I'll study what you've done and see if I can figure out how it works. I may be able to make some of the earlier string operations more efficient now too.
Thanks man, I owe you one.
Edit: lookahead! Who knew?
( ,
Sun 20 Apr 2008, 6:56,
archived)
I'll study what you've done and see if I can figure out how it works. I may be able to make some of the earlier string operations more efficient now too.
Thanks man, I owe you one.
Edit: lookahead! Who knew?

www.regular-expressions.info/lookaround.html#lookahead
Keep in mind that javascript doesnt support Lookbehind though, only Lookahead.
( ,
Sun 20 Apr 2008, 6:59,
archived)
Keep in mind that javascript doesnt support Lookbehind though, only Lookahead.

Up early. Is your sleeping not as well as it should be?
( ,
Sun 20 Apr 2008, 6:20,
archived)

thanks!you well apart from all this jibber jabber?


( ,
Sun 20 Apr 2008, 6:30,
archived)



All this jibber jabber is actually fun to be honest, as long as it gets sorted in the end :)
( ,
Sun 20 Apr 2008, 6:38,
archived)

split the string on "." (there is a Jscript command to do this - can't remember it tho) and check the left char of string 2, then re-assemble string (sucker) Re-iterate for other instances if any.
Sure you'll get away with previous tho!
God I'm such a nerd!
Good luck.
( ,
Sun 20 Apr 2008, 5:59,
archived)
Sure you'll get away with previous tho!
God I'm such a nerd!
Good luck.

The sequence you've described here would just be too inefficient in the context.
( ,
Sun 20 Apr 2008, 6:03,
archived)

he's on msn. but. if he is awake or not...
( ,
Sun 20 Apr 2008, 6:14,
archived)

$string=~s/(\.+)([^\s])/$1 $2/;
rephrasing your question as "replace one or more periods with the same number of periods and a space if the next character is not whitespace"
( ,
Sun 20 Apr 2008, 6:19,
archived)
rephrasing your question as "replace one or more periods with the same number of periods and a space if the next character is not whitespace"

that looks promising, thanks! And your rephrasing is much clearer, that's indeed exactly what I need.
But... the ~s at the beginning is unfamiliar. What does it do? It's possible it's used in JavaScript, but it may not be, not all of Perl's reg ex syntax is included.
Edit: Ok, I've tried this without the leading ~s and I'm getting an unhelpful javascript error... I think the problem is the repeated / near the end of the reg ex here... javascript uses / as the reg ex delimiter.
( ,
Sun 20 Apr 2008, 6:24,
archived)
But... the ~s at the beginning is unfamiliar. What does it do? It's possible it's used in JavaScript, but it may not be, not all of Perl's reg ex syntax is included.
Edit: Ok, I've tried this without the leading ~s and I'm getting an unhelpful javascript error... I think the problem is the repeated / near the end of the reg ex here... javascript uses / as the reg ex delimiter.

Good luck and have fun.
( ,
Sun 20 Apr 2008, 6:28,
archived)

~s/ is just the replace operator. For example ~s/old/new/ replaces 'old' with 'new'.
Perl has these auto variables $1, $2 etc that correspond to brackets () you put in the reg exp. I guess what's missing in your code above is the $2. that's what's removing your Y.
( ,
Sun 20 Apr 2008, 6:30,
archived)
Perl has these auto variables $1, $2 etc that correspond to brackets () you put in the reg exp. I guess what's missing in your code above is the $2. that's what's removing your Y.

I really appreciate your help.
I don't know if I can adapt the code sample you've given me, but the rephrasing is really helpful, I'm much clearer now about what I need to achieve.
Thanks!
( ,
Sun 20 Apr 2008, 6:35,
archived)
I don't know if I can adapt the code sample you've given me, but the rephrasing is really helpful, I'm much clearer now about what I need to achieve.
Thanks!

newString = oldString.replace(/\.(?!\.|\s)/g, ". ");
seems to work. English goes: Replace a "." which is not followed by a "." or a " "
but you know. i'm no expert.
( ,
Sun 20 Apr 2008, 6:41,
archived)
seems to work. English goes: Replace a "." which is not followed by a "." or a " "
but you know. i'm no expert.

which checks following characters without operating on them, very clever, why didnt I think of that.
COUGH
( ,
Sun 20 Apr 2008, 6:43,
archived)
COUGH

but I'm sure the question will resolve it's self in time.
just make sure you go before the journey
( ,
Sun 20 Apr 2008, 6:40,
archived)
just make sure you go before the journey

as you say, the question did resolve itself many times before. IN MY PANTS.
( ,
Sun 20 Apr 2008, 6:49,
archived)

newString = oldString.replace(/\.(?!\.|\s)/g, ". ");
seems to work. English goes: Replace a "." which is not followed by a "." or a " "
( ,
Sun 20 Apr 2008, 6:38,
archived)
seems to work. English goes: Replace a "." which is not followed by a "." or a " "

something i don't know about. looks like problem solved then
( ,
Sun 20 Apr 2008, 6:46,
archived)