function parseInt converts its first argument to a string, parses it, and returns an integer or NaN. If not NaN, the returned value will be the decimal integer representation of the first argument taken as a number in the specified radix (base). For example, a radix of 10 indicates to convert from a decimal number, 8 octal, 16 hexadecimal, and so on. For radices above 10, the letters of the alphabet indicate numerals greater than 9. For example, for hexadecimal numbers (base 16), A through F are used.

In the spec, 15.1.2.2/1 tells us that the conversion to string is performed using the built-in ToString, which (as per 9.8) yields "null" (not to be confused with toString, which would yield "[object Window]"!).

`parseInt("null", 24)`

Of course, this isn't a base-24 numeric string in entirety, but "n" is: it's decimal 23.

Now, parsing stops after the decimal 23 is pulled out, because "u" isn't found in the base-24 system:

If S contains any character that is not a radix-R digit, then let Z be the substring of S consisting of all characters before the first such character; otherwise, let Z be S. [15.1.2.2/11]

(And this is why parseInt(null, 23) (and lower radices) gives you NaN rather than 23: "n" is not in the base-23 system.)

This is very tragic behavior of parseInt (I was thinking why it was not design to though exception in these case). I would prefer to use NUMBER() instead when I can.

## javascript - parseInt(null, 24) === 23... wait, what? - Stack Overflow

javascript parseint

Assuming that you can use a random int generator, to pick characters from the strings of the alphabet and digits, to arrive at two arrays:

```const arrayOfLetters = ["H", "H", "H"];
const arrayOfNumbers = ["0", "0", "0"];```

the concept of interleaving is actually pretty simple:

```const interleave = (arr1, arr2) =>
Array.from({ length: arr1.length }) // or use Math.min or Math.max
.map((_, i) => [arr1[i], arr2[i]])
.reduce((a, b) => a.concat(b), []);

interleave(arrayOfLetters, arrayOfNumbers).join(""); // H0H0H0```

Interleaving an arbitrary number of arrays isn't really any harder.

The space division isn't technically part of the spec (and is also seen divided by hyphen). So if you really want to include it, or include space for it, then you can do something like:

```const generateCanadianPostalCode = (separator = " ") => {
const letters = generateLetters(3);
const numbers = generateNumbers(3);
const sequence = interleave(letters, numbers);
const halves = [
sequence.slice(0, 3).join(""),
sequence.slice(3).join(""),
];
return halves.join(separator);
};```

## javascript - generate fake postal code - Stack Overflow

javascript lodash

I'm not sure I understood you correctly, but from what I've gathered you want to have atleast one letter (a-z, 0-9) in the string. This regex will do just that: /^(?=.*[a-z\d]).+/igm

(Set the flags however they need to be set in asp.net. The m-flag might be redundant for you, I only used it for the demo. The g-flag likely does not exist. If so, just remove it.)

## asp.net - RegEx to check the string contains least one alphabet or dig...

asp.net regex

There is a neat implementation of the Luhn Mod N algorithm in the python-stdnum library ( see luhn.py). The calc_check_digit function will calculate a digit or character which, when appended to the file (expressed as a string) will create a valid Luhn Mod N string. As noted in many answers above, this gives a sanity check on the validity of the file, but no significant security against tampering. The receiver will need to know what alphabet is being used to define Luhn mod N validity.

## File containing its own checksum - Stack Overflow

checksum
`result = Regex.IsMatch(subjectString, @"\d\p{L}");`

will return True for your sample string. Currently, this regex also considers non-ASCII digits and letters as valid matches, if you don't want that, use @"[0-9][A-Za-z])" instead.

## c# - How to find out if a string contains digits followed by alphabet ...

c# regex

I'm not sure I understood you correctly, but from what I've gathered you want to have atleast one letter (a-z, 0-9) in the string. This regex will do just that: /^(?=.*[a-z\d]).+/igm

(Set the flags however they need to be set in asp.net. The m-flag might be redundant for you, I only used it for the demo. The g-flag likely does not exist. If so, just remove it.)

## asp.net - RegEx to check the string contains least one alphabet or dig...

asp.net regex

I'm guessing that the reason you want to use regular expressions is so that you don't mask every string that you get. This regex checks that there is at least 2 digits in the beginning of the string, then 0 to 3 alphabet characters, and then all the rest of the characters of the string need to be non-alphabet characters. If it matches, it masks the string, otherwise it says the string does not match.

```\$string = '0654535263';
if(preg_match('~^(\d{2})\d*?[a-zA-Z]{0,3}[^a-zA-Z]*\$~', \$string))
else
\$answer = \$string . ' does not match';

## regex - Regular expression matching in php - Stack Overflow

php regex
`^(?=[^ ]* ?[^ ]*(?: [^ ]*)?\$)(?=[^-]*-?[^-]*\$)(?=[^,]*,?[^,]*\$)[a-zA-Z0-9 ,-]*\$`

## .net - Regular expression to check the string containing Only alphabet...

.net regex

As far as i can judge, the cruial point is, how you generate the random token, and what alphabet you allow in this string. Assuming that you use the random source of the operating system to generate this 128 character string, and allow case sensitive characters and digits, you get a very strong and unpredictable "password".

• 128 characters are much longer than usual salted passwords, so salting is not necessary.
• It is impossible to brute-force 62^128 = 2E229 combinations. Dictionary attacks are out of question too because of the random nature of the token. That means iterating the hash-function is not necessary.

I would not use SHA-1 though, this reduces the entropy of your safe token to 160 bit. It doesn't make sense to create a super strong token, only to store part of it, instead use SHA-256 or SHA-512.

There are other things to consider, configure the cookie, so it can only be sent over HTTPS. Actually you will face the same problems as with maintaining a session.

## hash - Is Blowfish necessary for security token in PHP remember me sys...

php hash

You could try the below regex, in which the string must be start with alphabets followed by one or more digits and again followed by zero or more times alphabets or numbers.

`^[A-Za-z]+[0-9]+[A-Za-z0-9]*\$`

You could try the below regex if the input may or maynot contain numbers,

`^[A-Za-z]+[A-Za-z0-9]*\$`
• ^ Asserts that we are at the start.
• [A-Za-z]+ Allows one or more times alphabets(both uppercase and lowercase). + means repeat the preceding token one or more times. In our case the preceding token is the character class.
• [A-Za-z0-9]* Allows zero or more times alphabets or numbers. * means repeat the preceding token zero or more times.
• \$ End of the line.

The numeric is optional. The user can input without or with numeric in the middle of the string but there should be no special characters and it should start with alphabet

## c# - Regex validations in asp.net - Stack Overflow

c# asp.net regex
```>>> from string import punctuation
>>> text = 'i like: a, b, 007 and c!!'
>>> re.findall('\w+|[{0}]+'.format(punctuation),text)
['i', 'like', ':', 'a', ',', 'b', ',', '007', 'and', 'c', '!!']```
```>>> re.findall('\w+|\S+',text)
['i', 'like', ':', 'a', ',', 'b', ',', '007', 'and', 'c', '!!']```
`[{0}]`

substitutes the 0th argument to format which is punctuation. Takes any letter from punctuation.

your answer is elegant. A minor detail - i wished to group alphabets, digits and punctuation separately, whereas \w treats '_' also a word character. I guess replacing \w with [a-z0-9] in your solution should work. I am marking your answer as accepted. Thanks for your reply.

I didn't know that from reading the question but you can easily add that in as you said by adding more categories.

## python regex: how to split string into distinct groups based on alphab...

python regex

what you just described is refered to as a regular expression (although . means "anything" in regular expression).... there is already a library for this

also your example is wrong .. as "flow" would not match "fl*w" , however it would match "fl.w"

```import re
string2=string2.replace(".","[0-9a-zA-Z]")
print re.match(string2,string1)```

here is a statemachine implementation that should work for all cases except when it starts with *

```def matcher(pat,txt):
last = None
try:
for ltr in txt:
if ltr == pat:
pat = pat[1:] #consume
elif pat == "*" and ltr == last:
#dont consume
continue # dont change last
elif pat == "*" and ltr == pat:
pat = pat[2:] #consume 2 (* + whatever)
elif pat =="*"  and last == ".":
continue #dont consume and dont change last
elif pat == ".":
pat = pat[1:]#consume
elif pat == "*"  and ltr == pat:
pat = pat[3:] #consume 3 (x*X)
else:
return False
last = ltr
except IndexError:
return False #there was a problem that made it break ... it also doesnt match
if not pat or pat == "*":
return True

return False
print "Matching Pattern bo*k"
for word in "boak,bok,book,booooooook,boo,bk".split(","):
print word ," ?=",matcher("bo*k",word)```
```Matching Pattern bo*k
boak  ?= False
bok  ?= True
book  ?= True
booooooook  ?= True
boo  ?= False
bk  ?= True```

how would this be done without the use of the RE library?

you would need to implement a state machine ...

@user1530318 Why wouldn't you use the RE library? This is what it was built for...

This was an interview question that I completely blanked out on, just curious how it would be done

if it was an interview question and had to do with python they wanted you to use built ins ... not reinvent a complicated algorithm ... however to see how it constructs a state machine see osteele.com/tools/reanimator

## java - To check if two strings match with alphabets, digits and specia...

java python string compare character

I think what you want is to encode the ids using Base32. The resulting string contains only the 26 letters of the alphabet and the digits 2-7, making it very human readable.

## php - Turning an integer into random string and back again - Stack Ove...

php
`/^.*[a-zA-Z0-9][^a-zA-Z0-9]*\$/`

If you want only one alphabet or digit, followed by the same:

`/^[^a-zA-Z0-9]*[a-zA-Z0-9][^a-zA-Z0-9]*\$/`

I can't imagine what else it is that you are looking for. Examples would help immensely.

This fails in string "dfdfdf #\$#\$ fgf ( gd )". I want that string must have at least an alphabet or a digit. Only special characters or spaces should not be allowed as a string.

@Dev It works on that string

@bcurcio Or you can also check with "df s 7*&* (fdf) 009 Df (dfd)"

`^.*[a-zA-Z0-9][^a-zA-Z0-9]*\$`

## asp.net - RegEx to check the string contains least one alphabet or dig...

asp.net regex
```function brute(alphabet, match, int_start, int_stop){
var a = alphabet, al = 0,                     // for alphabet
m = match.toString(), ml = m.length,      // for our compare
i = int_start || 0, j = int_stop || 0,    // range of numbers to test
k = 0, l = 0, add = 0, sub = 0, diff = 0, // for building test string
test = '', found = false;                 // test string and result

if(i < 0) throw 'int_start must be at least 0';

if(a.constructor !== undefined){           // We need a string or array as
if( a.constructor.name !== 'String' && // our alphabet so we check for
a.constructor.name !== 'Array' )   // correct input and modify if
a = a.toString();              // necessary, or if we can't,
}
else throw 'Bad alphabet type';            // we throw an error

al = a.length;    // shorthand length

add = al;                             // when i=0, we start prefix here
while(add <= i - sub) sub += add,     // then work out what we have to

diff = add - sub; // shorthand to save calculations

while( i < j ){   // actual brute force loop starts here
test = '';       // empty any previous string
k = diff + i;    // convert our number from "x" to "1x"

while(k > 0){           // build it as a string
l = k % al;         // get index of digit
test = a[l] + test; // add digit to string
k = ( k - l ) / al; // move digits along
}

test = test.substring(1); // cut off the initial "1" we added

if(test.length === ml && test === m){ // compare test to what you want
found = true;
break;
}

i++;                  // prepare for our next loop
if(i - sub === add)   // and if we need another digit
sub += add,       // then recalculate our prefix
diff = add - sub; // update the shorthand
}

// brute force ended, let's see what we've got

if(found === false) i = -1; // if not found, return -1 as index

return [i, test, m]; // index found, string found with, what we were looking for
}```
`brute('0123abcd', '0c', 0, 20); // [14, "0c", "0c"]`

Thank you for your help but this is the reason why I said written explanations or just hints would be nice - you lost me right after the exception is thrown - from there I ....I don't really understand what's going on here :). If you'd care to clarify a bit that would be seriously awesome. But in any case thank you for trying to help.

After the first exception - check the type of the input for the alphabet, if it's not a string, convert it to a string (because you can do array style things on strings). After second exception is the complicated bit - if you want to count (e.g. in binary, base 2) 0, 1, 10, 11, 100, 101, 110, 111, that is EASY but if you want to do 0, 1, 00, 01, 10, 11, 000, 001, ..., that is much more difficult. One way to do it is to work a base above (e.g. base 3), which is what I did. Then loop over integer => chars.

To make it check against hashes you would change the line if(test.length === ml && test === m) to check the hash of test against what you want to find (i.e. if(myHash(test) === match))

It was bugging me then I noticed the method I did first was wrong (repeated itself in the middle) so I've changed it a LOT & added comments for nearly every line. New method prefixes an identity (1) on the front and then cuts it off so we get every outcome. @slagjoeyoco hope this is more helpful.

Hi and thanks a lot for adding the comments, very useful. Either it's my lack of coffee right now or I'm just plain stupid in terms of simple math, but after some thinking and fooling around with your code I'm left with two questions: 1) I now see what you're doing in the last if-check to find whether you need another digit or not, but: how on earth did you come up with this sourcery?! :) Is there an easier way to find this out? I mean, how did you know what these numbers will always play out? Sry for the confused question now but I really don't know how else to ask...

## implementing brute force attacks on hash values in Javascript - Stack ...

javascript hash brute-force cracking
```import re
if re.findall(regex, string):
print "You found it!"```

## java - To check if two strings match with alphabets, digits and specia...

java python string compare character

If I understand what you want right (you want to find a subsequences of a large string that are equal to a given set of strings of length 32), and your alphabet has a reasonable size (letters, digits and punctuation, for instance), then you can do the following:

This way you spend O(l * n) time to preprocess, but then for each small string in your set you only do O(m) work where m is the length of that string.

## java - fuzzy fast string matching and indexing algorithm - Stack Overf...

java string algorithm search indexing