Re: Regular Expression Question

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



As does:
<script type='text/javascript'>
document.write("aaa1234567b45454bb".
replace(/.*?(\d)(?=(\d{3}))|.+$/g, "$1$2,").replace(/,+$/,""))
</script>

The second replace merely gets rid of trailing commas.

The first replace, doing the heavy lifting, says: eat chars
until there's a digit (that's the (\d), which we'll call $1)
followed by three other digits (which we'll call $2). When
that happens, replace $1 (and the prior characters) with:
$1 followed by $2 followed by ","

Characters now continue to be eaten starting from the char
following the $1 (in the original string). The eating does
not start from after the $2 because $2 was embedded within
a forward lookahead, namely the (?=...), so that the $2
chars did not get eaten in the prior part. Finally,
that |.+$ is there because once we get to the last set of 4
contiguous digits, we want to replace the remainder of the
string with the empty string (or more precisely, a comma),
so those final characters have to get eaten somehow (and
the plus ensures there is at least one character to eat).

This is a slight adaptation from the last part
of my Nov. 19 post in this same thread:
http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_frm/thread/82238d66a934a547

Csaba Gabor from Vienna
.



Relevant Pages

  • Re: Worrying
    ... if you need to enter the nth and mth chars then the password ... You need some way to be able to enter the Mth and Nth characters, ... You don't actually need to be able to recover ... next time I called, she asked me for the 1st and 3rd digits, she'd be able ...
    (uk.misc)
  • Re: Looking for .COM->"ASCII" .COM util
    ... to work entirely within an even smaller character set: digits + ... I.e. for each pair of decoded chars 13 bits pops out: The lower 8 bits are immediately written to the output buffer, while the top 5 bits are combined with any previous 5-bit chunks. ... If the ONLY characters that are required are the 10 decimal ...
    (comp.lang.asm.x86)
  • Re: Paper & pencil password algorithm
    ... currently I am using a 10x10 Polybius square. ... How would you convert base 11 digits to base 10 digits with uniform ... characters to find on the keyboard. ... I'm undecided on whether it should be 2 or 3 foldsums. ...
    (sci.crypt)
  • Re: Question for the math wizards...
    ... string of characters that isn't too long, ... bits per character with base-32 encoding, then we are limited to shipping ... to know if it was possible given m to map m via a function Fto an m' ... In real world terms, say n is 100 digits, m is 50 digits, and I want to ...
    (sci.crypt)
  • Re: unix filename restriction
    ... underscore _ and the dot. ... You could use other characters, ... never met a *human* defined path of more than 80 chars (most of the ... If you want to be very sure, limit your filename to the DOS limit of 8 ...
    (comp.os.linux.development.apps)