Question

In: Computer Science

Write a regular expressions that would match lines in text that contain word DATE: at the...

  1. Write a regular expressions that would match lines in text that contain word DATE: at the beginning of a line followed by actual date in format YYYY-MM-DD. Space between colon ( : ) and date may or may not exist.
  2. In C, if you issue the following statement n << 2 where n is an integer, what will be value of n?

Solutions

Expert Solution

Regular Expression to validate Date:YYYY-MM-DD is

([D][a][t][e][:][12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))

Java program used for varify:

public class Main
{
        public static void main(String[] args) {
           String str="Date:2016-11-15";
                System.out.println(str.matches("([D][a][t][e][:][12]\\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01]))"));
        }
}

Varify in java: (Note: In program we use \\d instead of \d because if we use only \d compiler take it as a space character)

Output 1:

Output 2:

Output 3:

Output 4:

Answer 2:

In c << is a left shift operator.

n<<c is equivalent to multiplying n with 2c

Suppose value of c=2 and value of n=4

then it is 4*22 =4*4=16

C program used for varify:

#include <stdio.h>

int main()
{
   int n=4;
   printf("value of n<<2 is %d",n<<2);
   

    return 0;
}

Output 1: (here value of n is taken 0 by default by compiler)

So it solve like: 0*22=0

Output 2:


Related Solutions

Write a regular expressions that would match lines in text that contain word DATE: at the...
Write a regular expressions that would match lines in text that contain word DATE: at the beginning of a line followed by actual date in format YYYY-MM-DD. Space between colon ( : ) and date may or may not exist. In C, if you issue the following statement n << 2 where n is an integer, what will be value of n? In bash, if you define variable var = “date” and issue a statement echo `$var`, what output will...
Define a regular expression that will correctly (and exactly) match a valid Gregorian calendar date of...
Define a regular expression that will correctly (and exactly) match a valid Gregorian calendar date of the form MM/DD/YYYY (with leading zeroes for single-digit months and days) (and ONLY dates in this format). • Months 1, 3, 5, 7, 8, 10, and 12 have 1–31 days • Months 4, 6, 9, and 11 have 1–30 days • Month 2 (February) has 1–28 days (ignore leap years) • Assume that the year falls into the range 1900–2099 HINT: You may find...
Regular Expressions Assignment Write a regular expression for each of the following. Can you show output...
Regular Expressions Assignment Write a regular expression for each of the following. Can you show output please. A blank line (may contain spaces) Postal abbreviation (2 letters) for State followed by a space and then the 5-digit zip code A KU student username (Ex. lpork247) A “valid” email address (also explain how you defined “valid”) A SSN pattern (ddd-dd-dddd)
QUESTION: Write regular expressions after the ► to validate the following inputs: a) Product codes that...
QUESTION: Write regular expressions after the ► to validate the following inputs: a) Product codes that have one or more letters followed by one or more digits. ► b) Nonnegative integers between 1,000 and 9,999, including the comma. ► c) Canadian zip code containing upper case characters only. ► d) License plate numbers that have the form:          Letter          Digit          Letter          Hypen (-)          Digit          Letter          Digit ►
Write a program to convert a text-file containing expressions (one per line) into post-fix expressions outputted...
Write a program to convert a text-file containing expressions (one per line) into post-fix expressions outputted to a file of your choice using a stack with one space between operators and variables (one letter variables) and/or constants (one digit constants). IN PYTHON please
Write a program to convert a text-file containing expressions (one per line) into post-fix expressions outputted...
Write a program to convert a text-file containing expressions (one per line) into post-fix expressions outputted to a file of your choice using a stack with one space between operators and variables ( one letter variables) and/or constants (one digit constants).
The user is going to cin a whole bunch of regular text. You store each word...
The user is going to cin a whole bunch of regular text. You store each word based on its first letter. Print out all the words they used by letter. Strip all punctuation and uncapitalize everything. : - Project set up with stl includes, correct files, and turned in correctly. (Zipped project with no inner debug folder.) - Basic data structure made. This requires at least two connected containers. More is okay if it makes sense to you, but no...
Question d) Write the regular expression statement that will match a string that starts with the...
Question d) Write the regular expression statement that will match a string that starts with the word "Warning" following by one space and then a number of any number of digits. Question e) Write the regular expression statement that will match a string that ends with the phrase "End of Report. Question f) Write the regular expression statement that will match a string that starts with the phrase "Begin Log:" then contains a collection of characters (other than newline) followed...
Write regular expressions that describes the following language: The language over {0,1,/} that contains all and...
Write regular expressions that describes the following language: The language over {0,1,/} that contains all and only the strings that are base-2 (as above, you can use base-10 if you prefer) representations of rational numbers. Define a representation of a rational number to be either a representation of an integer, or two representations of integers separated by “/”. Leading 0s are allowed this time.
Write regular expressions that describes the following language: The language over {0,1} that contains all and...
Write regular expressions that describes the following language: The language over {0,1} that contains all and only the strings that are base-2 representations of odd positive integers. Do not allow leading 0s. (If you are more comfortable writing bulky regular expressions than you are working in base-2, you may write a regular expression for strings that are base-10 representations of odd integers without leading 0s, using alphabet {0,1,2,3,4,5,6,7,8,9}.)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT