Could someone check if these product and sum rule questions are correct? - counting

Are these correct if not can I get an explanation thanks!
1) A string has the form 0???0, where each ? could be a 0 or a 1. How many possible strings are there?
Would it be 6 possible strings?
2)Suppose a license plate number in this state can only contain capital​ letters and digits and can only be any string of the form:
Letter-Letter-Letter-Digit-Digit-Digit-Digit
How many different license plate numbers are possible?
Would it be 10^4⋅26^3 different license plates?
3)Suppose a license plate number in this state can only contain capital​ letters and digits and can only be any string of the form:
Letter-Letter-Letter-Digit-Digit-Digit-Digit
How many license plate numbers are possible if no digit appears more than once?
Would it be 10⋅9⋅8⋅7⋅26^3
4) Suppose a license plate number in this state can only contain capital​ letters and digits and can only be any string of the form:
Either-Letter-Letter-Digit-Digit-Digit-Digit
where "Either" means it can be either Capital letter or digit.
How many different license plate numbers are possible?
Would it be (26+10)(26^2)(10^4)

Related

How to match any word in parenthesis but with 2 capital letters at least?

From this text:
[1] "Percentage of Participants Who Achieved a 75% Improvement (Response) in the Psoriasis Area Severity Index (PASI-75) at Week 16 From Baseline"
[3] "Percentage of Participants Who Achieved a Static Physician Global Assessment (sPGA) Score of Clear (0) or Almost Clear (1) With at Least 2 Points Reduction From Baseline"
[15] "Change From Baseline in the Mental Component Summary (MSC) Score of the Medical Outcome Study Short Form 36-item (SF-36) Health Survey Version 2.0 at Week 16"
I want to match: PASI-75, sPGA, MSC, SF-36, so not 'Response', not (1) nor (0).
The regex I want use should be something like:
\([a-zA-Z0-9-]*&[A-Z]{2,}\) but don't know how to express & here. Some thread suggested (?=query1)(?=query2) but it doesn't work here.
Try \([^\)]*[A-Z]{2}[^\)]*\)
This matches a (, zero or more non-) characters, two upper-case letters, zero or more non-) characters, and a ).
An alternative that allows for non-consecutive capitals, but still restricts to matching a single word:
\([^\)]*[A-Z][^\)]*[A-Z][^\)]*\)
This matches a (, zero or more non-) characters, one upper-case letter, zero or additional non-) characters, one upper-case letter, zero or more non-) characters, and a ).
Assuming (from your example) you want to match any non-whitespace character enclosed within parenthesis, I would say that the simplest solution will be:
\(\S*[A-Z]{2}\S*\)
What you want is lookahead.
The regex engine will first try to match two capital letters.
Like this:
\b\((?=[A-Z]{2})[a-zA-Z0-9]*\)\b
(?=[A-Z]{2}) tells the engine to look for two capitals first.
It will skip the whole word if it can't find two capitals.

What constitutes a valid symbol (identifier) in R

I can’t find a spec of the language…
Note that I want a correct answer, e.g. like this, as i could easily come up with a simple, but likely wrong approximation myself, such as [[:alpha:]._][\w._]*
The documentation for make.names() says
A syntactically valid name consists of letters, numbers and the dot or underline characters and starts with a letter or the dot not followed by a number. Names such as ".2way" are not valid, and neither are the reserved words.
The definition of a letter depends on the current locale, but only ASCII digits are considered to be digits.
#Roland points out this section of the R language definition:
10.3.2 Identifiers
Identifiers consist of a sequence of letters, digits, the period (‘.’) and the underscore. They must not start with a digit or an underscore, or with a period followed by a digit.
The definition of a letter depends on the current locale: the precise set of characters allowed is given by the C expression (isalnum(c) || c == ‘.’ || c == ‘_’) and will include accented letters in many Western European locales.
Notice that identifiers starting with a period are not by default listed by the ls function and that ‘...’ and ‘..1’, ‘..2’, etc. are special.
Notice also that objects can have names that are not identifiers. These are generally accessed via get and assign, although they can also be represented by text strings in some limited circumstances when there is no ambiguity (e.g. "x" <- 1). As get and assign are not restricted to names that are identifiers they do not recognise subscripting operators or replacement functions.
The rules seem to allow "Morse coding":
> .__ <- 1
> ._._. <- 2
> .__ + ._._.
[1] 3

Combining 2 regular expression in web.config passwordStrengthRegularExpression=""

I am not able to combine below two regular expressions. Password standard requirement:
Password cannot contain your username or parts of your full name
exceeding two consecutive characters
Passwords must be at least 6 characters in length
Passwords must contain characters from three of the following categories
Uppercase characters (English A-Z)
Lowercase characters (English a-z)
Base 10 digits (0-9)
Non-alphabetic characters (e.g., !, #, #, $, %, etc.)
Expression:
passwordStrengthRegularExpression="((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[##$%]).{6,20})"
Passwords cannot contain the word “Test” or “test” or variants of the word
passwordStrengthRegularExpression="((?=.*\"^((?!Test|test|TEST).*)$"
Both are working fine individually.
Because your second regexp primarily uses a negative lookahead, you can remodel that slightly and stick it right at the beginning of the other expression. First, I'm going to change your second regex to:
"(?!.*(?:Test|test|TEST))"
In english, the string may not contain any number of (or zero) characters followed by test.
Then, I'm going to stick that right at the beginning of your other expression
passwordStrengthRegularExpression="^(?!.*(?:Test|test|TEST))(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[##$%]).{6,20}$"
Finally, I'm going to show you how to make only one part of a regex case-insensitive. This may or may not be supported depending on what program this is actually for.
passwordStrengthRegularExpression="^(?!.*(?i:test))(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[##$%]).{6,20}$"
See the (?i:...)? That means that the flags between the ? and the : are applied only to that part of the expression, that is, only that area is case-insensitive.
Combining your requirements and https://stackoverflow.com/a/2860380/156388 i've come up with this:
(?=^[^\s]{6,}$)(?!.*(?i:test))((?=.*?\d)(?=.*?[A-Z])(?=.*?[a-z])|(?=.*?\d)(?=.*?[^\w\d\s])(?=.*?[a-z])|(?=.*?[^\w\d\s])(?=.*?[A-Z])(?=.*?[a-z])|(?=.*?\d)(?=.*?[A-Z])(?=.*?[^\w\d\s]))^.*
Dont think your first regex is actually working fine if you want to meet the requirements in bullets above it. Clamps to 20 chars but doesn't say you have to. Requires all four of the categories but requirements says 3 of the 4. Doesn't check the username requirement at all. So I've gutted out most of the initial regex.
It matches these (as expected):
Short5
TeSamplePrd6
TEBREaKST6
WinningUser6#
It fails on these (as expected):
SamplePassword
TestUser6#
Shrt5
TeSTTest
Remaining problems
For some reason it matches this:
TEBREKST6
but it only meets two of the four requirements + min length - not sure why?
There is nothing taken into account about the "Password cannot contain your username or parts of your full name exceeding two consecutive characters" requirement and I'm not sure you can even do this through web.config min password requirement as you dont have access to it within the regex.

Phone number regex

I need regular expression for phone number.
(from 0 to 9) (total 10 digits)
Example: "0123456789"
Normally a \d{10} would do the trick. But that is the lazy-man's way of validating as '0000000000' would pass a a valid entry.
But in case you know more about the domain, and the rules (I mean, if your phone number belongs to a specific country) and you want to make sure the number matches the local rules, then you can be a little bit more specif.
For example if all the numbers are starting with a leading zero, you can do this
0\d{9}
Or if the prefixes are well know... you can make an expression that allows phone numbers only starting with certain prefix(es).
(017|016|019|012)\d{7}
This will allow only those prefixes in the list, plus other 7 digits.
Use this pattern and match it:
\d{10}
\d : digits only.
{n}: numbers of occurrences.
You can refer this post for more info. Regex for Phone number
its simple:
\d{10}
\d allows digits, and {10} indicates that the phone number must be exactly 10 digits long.
As you mentioned in the comment that you also want a regex for 012-345-6789, (\d{3}-){2}\d{4} would do the work.
(\d{3}-) would validate the first 3 digits and a -
(\d{3}-){2} would look for two occurrence of the above described group. So will validate: 012-345- And at last \d{4} will look for the last 4 digits

Regular expression in ASP.net

I wrote regular expression for phone no as ^[0]\d{9,10} (phone no should start with 0). This works fine.
But I want to omit the option repeating 0's. i.e 0000000000
How can I add this bit to it.
^0(?!0*$)\d{9,10}$
might be what you want.
The first number is a 0.
The (?!0*$) negative lookahead ensures that the rest of the string is not all zeroes.
And finally \d{9,10} matches any 9 or 10 digits.
You could specify [1-9] as the second digit instead of \d, like so:
^[0][1-9]\d{8,9}$
(I presume the rest of the digits could still be zeros)
I do note that your phone number format is fairly limited. For example, it doesn't allow for international numbers (starting with a plus sign), nor for any common formatting characters such as brackets spaces or hyphens. It also assumes that all phone numbers will be 10 or 11 digits long, which is (mostly) true in the UK and probably other countries, but may not always be the case.
Depending on the requirements of your system, you may want to adjust to take some of those points into account.

Resources