This question already has an answer here:
Regular expression for password complexity
(1 answer)
Closed 8 years ago.
I'm trying to have the following rules for NSString validation using regular expression:
8 characters minimum length
at least 1 digit
at least 1 uppercase
at least 1 lowercase
I'm only able to do the following to get the first rule like this:
^[a-zA-Z0-9]{8,}$
Which if i understand correctly check for minimum 8 characters length with lower/uppercase and digit
Thank you
Use a lookahead for each assertion:
(?=.*\d)(?=.*[A-Z])(?=.*[a-z])^.{8,}$
Related
This question already has answers here:
Understanding slicing
(38 answers)
Closed 1 year ago.
def add_binary(a,b):
return bin(a+b)[2:]
Why is "[2:]" used here?
convert number into it's binary and remove first two characters 0b.
Example:
Original number: 10
Binary string: 0b1010
after that it will be 1010 only.
This question already has answers here:
Validation issue in email for minimum length in javascript
(2 answers)
regex for email validation (minimum characters) [closed]
(2 answers)
Email validation- characters length before # and before dot
(3 answers)
Limit length of characters in a regular expression
(6 answers)
Closed 2 years ago.
For example {limit [5-50] for here}#email.com
email#hotmail.com -> incorrect, because count of characters input smaller then 5
tryemail#hotmail.com -> correct
Can you explain the solution ?
Maybe as simple as this:
local_part, domain = email.split('#')
local_part.length < 5
Though keep in mind many people do have short addresses, so don't get too strict here.
You could also do this with a regular expression:
email.match?(/\A[^#]{5,50}#[^#]+\z/)
Where that's an extremely lax parser.
This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 3 years ago.
I need to create a regex which contains at least 1 special character, and at least 1 number with alphabets.
You may try the following pattern:
^(?=.*[0-9])(?=.*[^A-Za-z0-9])(?=.*[A-Za-z]).*$
Explanation:
(?=.*[0-9]) assert one number present
(?=.*[^A-Za-z0-9]) assert one special character present
(?=.*[A-Za-z]) assert one alpha present
Note that I have defined a special character as being anything not alphanumeric. If instead you have a list of special characters, then you can modify the middle lookahead in my pattern.
This question already has answers here:
Is this response from the compiler valid?
(3 answers)
Closed 8 years ago.
I am getting error message:
prefix/postfix '=' is reserved
for below simple in swift.
var c=0,a=2,b=4
c= a+b
any idea why I am getting this error?
Check this:
Is this response from the compiler valid?
Swift isn't entirely whitespace-agnostic like C... in particular, it uses whitespace to distinguish prefix from postfix operators (because ++i++ in C is a grammar oddity). But it's not ridiculously strict about whitespace like Python either.
P.S. So you have to add whitespace before =.
If I use a single space after variable "c" name, this error is get removed.
c = a+b
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
"Rubymonk Is Pretty Brilliant".match(/ ./, 9)
How is the answer "P" calculated from this regex?
use the match method on the string
passes two arguments, a regular expression and the position in the string to begin the search.
returns the character 'P'
The criteria you posted from the Rubymonk grader answer this succinctly:
passes two arguments, a regular expression and the position in the
string to begin the search
But let's examine that in more detail. match is being passed two arguments:
/ ./, a regular expression
9, the starting position in the string
The regular expression tells us that we're looking for a space () followed by any character (.).
The starting position tells us to start at position 9 (I). So instead of applying that regex against "Rubymonk Is Pretty Brilliant", we're applying it against "Is Pretty Brilliant".
In the string "Is Pretty Brilliant", where is the first place we encounter a space followed by another character? "Is[ P]retty Brilliant", right? Thus match finds a result of P (that's space-P, matching the regex, not just P.)
To see this more clearly and to experiment further with regexes, you can try it in an irb session or in your browser using Rubular.
(Just google for RegEx + ruby, You will find explanation of regex syntax)
/ANYTHING-HERE/
Will look for ANYTHING-HERE in the text.
In Your example its (/ ./,9):
/SPACE DOT/
So it will look for space followed by single character (Dot -> single character).
9 will be "I" from the string. And that is not space, so it will go on 2 characters right. Will find space, and then will find single character "P".
That is the result.