Question

In: Computer Science

Write the RE for identifiers that can consist of any sequence of letters (l) or digit...

Write the RE for identifiers that can consist of any sequence of letters (l) or digit (d) or "_"
but the first char must be a letter and the last char cannot be a "_" (10)

Solutions

Expert Solution

RE is

/^(([A-Za-z])|([A-Za-z][A-Za-z0-9_]*[A-Za-z0-9]))$/

What each word signify:

^ : start of string
[ : beginning of character group
a-z : any lowercase letter
A-Z : any uppercase letter
0-9 : any digit
_ : underscore
] : end of character group
* : zero or more of the given characters
| : or operation
( : used for grouping regex
):used for grouping regex
$ : end of string

It can be divided into two parts:

  • First one [A-Za-z] which means the first character can be just from Capital A-Z or Small a-z and also it is the last character so that means a string with only one value so it will be just a letter as first character needs to be a letter and last one cannot be underscore
  • There is | - OR in between the first and second part
  • Second one can be broken into three parts:
    • First one [A-Za-z] which means the first character can be just from Capital A-Z or Small a-z
    • Second part [A-Za-z0-9_]* which all the characters in between can be from Capital A-Z or Small a-z or digit 0-9 or an underscore and this can occur zero or multiple times so * is placed outside the bracket
    • Then comes the third and the last part [A-Za-z0-9] in which it can be from Capital A-Z or Small a-z or digit 0-9 but not an underscore and will be the last character it can be only one letter or a digit

The first part is their to help regex use for a single letter input every other case will handled by the second part


Related Solutions

Write the RE for identifiers that can consist of any sequence of letters (l) or digit...
Write the RE for identifiers that can consist of any sequence of letters (l) or digit (d) or "_" but the first char must be a letter and the last char cannot be a "_"
Describe the rules governing identifiers. Can identifiers be re-used in the same Java class file? Provide...
Describe the rules governing identifiers. Can identifiers be re-used in the same Java class file? Provide three examples of different kinds of invalid identifiers. Java
1An identification code is to consist of 2 letters followed by 5 digit. Determine the fallowing?...
1An identification code is to consist of 2 letters followed by 5 digit. Determine the fallowing? 1a) how many different codes are posible if repetition is permitted? 1b) how many different codes are possible if repetition is not permitted, but the first 2 letters must ve the same letter? 1c) how many different codes are possible if the first letter must be, P, Q, R, S, T, and repetition for everything else is not permitted?
Write a regular expression that can represent any digit, without more than one digit or non...
Write a regular expression that can represent any digit, without more than one digit or non digit characters.
write a program that uses exactly four for loops to print the sequence of letters below...
write a program that uses exactly four for loops to print the sequence of letters below A A A A A A A A A A B B B B B B B C C C C C C E E E E E
How many: New York license plates can be made that consist of 3 letters followed by...
How many: New York license plates can be made that consist of 3 letters followed by 4 numbers given the restriction that if the first letter is an ‘N’, then the second letter must be a ‘Y’? New York license plates can be made that consist of 3 letters followed by 4 numbers given the restrictions that (1) if the first letter is an ‘N’, then the second letter must be a ‘Y’ and (2) if the second letter is...
The user enters some text into a textbox. It can contain any characters (letters, digits, spaces,...
The user enters some text into a textbox. It can contain any characters (letters, digits, spaces, punctuation marks, and there is no length limit). When a button Count is hit , display the number of upper-case letters in the inputted phrase. This must be done in visual studios using C#.
How can I re-write the following questions as closed-ended questions to be included in a questionnaire?...
How can I re-write the following questions as closed-ended questions to be included in a questionnaire? 1. Do agree that the World Bank were able to measure the degree to which loan conditions were implemented in Emerging Markets when political influences favored policy reforms during the fall-out of the 2008 Global Economic Crisis. 2. In response to the 2008 Global Economic Crisis, do agree that the World bank efficiently reduced poverty by increasing lending in larger degrees to middle income...
I am completing a questionnaire for my course. How can I re-write following questions as closed-ended...
I am completing a questionnaire for my course. How can I re-write following questions as closed-ended questions to be included in the questionnaire? 1.Do you believe that World Bank loans significantly helped economic development in Emerging Markets during 2008-2016. 2. Please indicate the extent to which you agree with the following statements: a) The World Bank helped improve the enabling environment for SME firms in Emerging Markets during 2008-2016. b) The World Bank’s mainstreaming of framework agreements addressed project implementation...
Programming. Write only code for the following. Do not write any comments. You can submit your...
Programming. Write only code for the following. Do not write any comments. You can submit your answer as .java file(s). #1. Design a Java JProduct class for a product which implements both cloneable and comparable interfaces The class should have the following private member variables: m_id: an integer that holds the product ID m_name: a string that holds the product name m_wholesaleprice: a double that holds the wholesale price m_retailers: a String array that holds all retailers who sell the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT