## Interview Question

• 0

Country: India

Comment hidden because of low score. Click to expand.
0
of 0 vote

pattern = "expr1 OR expr2"

exrp1 = [A-Za-z][0-9][A-Za-z][0-9][A-Za-z][0-9][A-Za-z][0-9]
exrp2 = [0-9][A-Za-z][0-9][A-Za-z][0-9][A-Za-z][0-9][A-Za-z]

Limitation: special chars can't be considered here

Comment hidden because of low score. Click to expand.
0

'1abcdefg' is not covered here!

Comment hidden because of low score. Click to expand.
0

correct... still finding sol... I guess by just reg exp we can't the sol....

Comment hidden because of low score. Click to expand.
0
of 0 vote

``str.matches("[A-Za-z0-9]{8}")``

Comment hidden because of low score. Click to expand.
0

'aabbccdd' is valid which is wrong.. atleast one number should be there..

Comment hidden because of low score. Click to expand.
0
of 0 vote

Warning: this method is pretty inefficient, but it should work.

``````for i in range (8):
for j in range(8):
if i != j:
for k in range (8):
if k == i:
string = string + r"\d"
elif k == j:
string = string + r"[a-zA-Z]"
else:
string = string + r"."
if i != 7 or j != 6:
string = string + r"|"``````

String will be your regular expression at the end

Essentially, this determines all possible positions of the two necessary characters, and creates a regular expression that takes them into account. I'd advise against this method if you can think of a better manner, but it should produce a working regex.

Edit: Another method using a couple of regexes, run

``"^........\$"``

After this, run the second expression which another user listed above:

``".*\d+.*[a-zA-Z]+.*|.*[a-zA-Z]+.*\d+.*"``

Still looking for a single expression that is more efficient than the previous one I listed, no luck so far.

Comment hidden because of low score. Click to expand.
0
of 0 vote

^\d[A-Za-z]......|\d.[A-Za-z].....|\d..[A-Za-z]....|\d...[A-Za-z]...|\d....[A-Za-z]..|\d.....[A-Za-z].|\d......[A-Za-z]|[A-Za-z]\d......|.\d[A-Za-z].....|.\d.[A-Za-z]....|.\d..[A-Za-z]...|.\d...[A-Za-z]..|.\d....[A-Za-z].|.\d.....[A-Za-z]|[A-Za-z].\d.....|.[A-Za-z]\d.....|..\d[A-Za-z]....|..\d.[A-Za-z]...|..\d..[A-Za-z]..|..\d...[A-Za-z].|..\d....[A-Za-z]|[A-Za-z]..\d....|.[A-Za-z].\d....|..[A-Za-z]\d....|...\d[A-Za-z]...|...\d.[A-Za-z]..|...\d..[A-Za-z].|...\d...[A-Za-z]|[A-Za-z]...\d...|.[A-Za-z]..\d...|..[A-Za-z].\d...|...[A-Za-z]\d...|....\d[A-Za-z]..|....\d.[A-Za-z].|....\d..[A-Za-z]|[A-Za-z]....\d..|.[A-Za-z]...\d..|..[A-Za-z]..\d..|...[A-Za-z].\d..|....[A-Za-z]\d..|.....\d[A-Za-z].|.....\d.[A-Za-z]|[A-Za-z].....\d.|.[A-Za-z]....\d.|..[A-Za-z]...\d.|...[A-Za-z]..\d.|....[A-Za-z].\d.|.....[A-Za-z]\d.|......\d[A-Za-z]|[A-Za-z]......\d|.[A-Za-z].....\d|..[A-Za-z]....\d|...[A-Za-z]...\d|....[A-Za-z]..\d|.....[A-Za-z].\d|......[A-Za-z]\d\$

This is "OR" of all permutations of "1a......". Yes, autogenerated, readonly, but it works

Comment hidden because of low score. Click to expand.
-1
of 1 vote

.*[A-Za-z]+.*[0-9]+.*|.*[0-9].*[A-Za-z]+.*

There are 2 parts to this regular expression.

Comment hidden because of low score. Click to expand.
0

about length which should be only 8??

Comment hidden because of low score. Click to expand.
0

@betacod3r:
-As cobra said what about length should be exactly 8 and
-if we create any regular exp which takes exactly 8 char need to take care of special char also.

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.