Blog

MCQs

Disclaimer:

Educational Use Only:

The website links provided are to be used strictly for educational and knowledge-gaining purposes only.

No Misuse:

Do not misuse the links or the information contained therein for any commercial, illegal, or unethical activities.

Respect for Websites and Businesses:

Respect the intellectual property and business interests of the websites and their owners. Do not attempt to alter, copy, or redistribute content without proper authorization.

Acknowledge Value of Knowledge:

Recognize and value the knowledge and resources shared by these websites. Use the information responsibly and ethically.

No Endorsement:

The provision of these links does not imply endorsement of the linked sites, their content, or their products and services. Users are responsible for evaluating the suitability and accuracy of the information.

User Responsibility:

By accessing these links, you agree to use the information at your own risk and to comply with all applicable laws and website terms of use.


Overall MCQs for Reference

  1. Which symbol in regular expressions denotes zero or more occurrences of the preceding element?
    a. +
    b. *
    c. ?
    d. $
    Answer: b. *testbook​
  2. What regular expression represents all strings starting with ‘a’ over the alphabet {a, b}?
    a. a(a+b)
    b. a(a+b)*
    c. a*
    d. a*(a+b)*
    Answer: b. a(a+b)*t4tutorials​
  3. Which operation are regular expressions closed under?
    a. Union
    b. Intersection
    c. Kleene star
    d. All of these
    Answer: d. All of theset4tutorials​
  4. What does the regular expression ab match?
    a. All strings consisting of any number of ‘a’s followed by any number of ‘b’s
    b. All strings starting with ‘a’ and ending with ‘b’
    c. Only strings that alternate between ‘a’ and ‘b’
    d. Only the empty string
    Answer: a. All strings consisting of any number of ‘a’s followed by any number of ‘b’stestbook​
  5. Which type of machine accepts regular languages?
    a. DFA
    b. PDA
    c. LBA
    d. Turing machine
    Answer: a. DFAsanfoundry​
  6. What does the regular expression ab* represent?
    a. One ‘a’ followed by zero or more ‘b’s
    b. Zero or more ‘a’s followed by one ‘b’
    c. Any string containing ‘ab’
    d. Only the string “ab”
    Answer: a. One ‘a’ followed by zero or more ‘b’st4tutorials​
  7. In regular expressions, what does the symbol “|” denote?
    a. Concatenation
    b. Union
    c. Intersection
    d. Complement
    Answer: b. Uniont4tutorials​
  8. Which regular expression matches all strings ending with ‘b’?
    a. (a+b)b
    b. b(a+b)

    c. (ab)
    d. (b*)a
    Answer: a. (a+b)*bt4tutorials​
  9. What is the regular expression for strings containing only even number of ‘a’s?
    a. (baba)*
    b. (baa)
    c. (a+b)*
    d. (aabb)*
    Answer: b. (baa)scribd​
  10. For digit extraction, which regular expression segment denotes any four digits?
    a. d{4}
    b. \d{4}
    c. [0-9]{4}
    d. (0-9){4}
    Answer: b. \d{4}librarycarpentry.github​
  11. What does the regular expression [A-Za-z]+ match?
    a. All digit strings
    b. All non-alphabet strings
    c. All alphabetic strings
    d. All symbols
    Answer: c. All alphabetic stringslearn.microsoft​
  12. Which is a valid regular expression for matching consecutive a’s over {a, b}?
    a. (aa+b)
    b. aa(b)*
    c. (aa+b)*
    d. None of these
    Answer: c. (aa+b)*t4tutorials​
  13. What is Kleene star in regular expression?
    a. Repetition zero or more times
    b. Repetition exactly once
    c. Optional inclusion
    d. Grouping operation
    Answer: a. Repetition zero or more timestestbook​
  14. Choose the regular expression for where every ‘a’ in a string is tripled.
    a. aaa*
    b. (aaa+b)*
    c. (a+aa)*
    d. (b+aaa)*
    Answer: b. (aaa+b)*scribd​
  15. Which regular expression denotes an empty string?
    a. ∅
    b. ε
    c. a*
    d. (a+b)*
    Answer: b. εcesaraguilar.weebly​
  16. What regular operation is not supported in basic regular expressions?
    a. Union
    b. Intersection
    c. Kleene star
    d. Concatenation
    Answer: b. Intersectiont4tutorials​
  17. How many strings of length 3 does (a+b)* generate?
    a. 6
    b. 8
    c. 9
    d. 12
    Answer: b. 8sanfoundry​
  18. Match the following: Lexical analysis is commonly implemented using:
    a. Regular expressions
    b. Pushdown automata
    c. Turing machines
    d. Context-free grammars
    Answer: a. Regular expressionstestbook​
  19. Which string does not match with aa(bb)*?
    a. aabb
    b. aabbbb
    c. aa
    d. ab
    Answer: d. abt4tutorials​
  20. Which method is used in Python to find all occurrences of a pattern in a string using RegEx?
    a. match()
    b. findall()
    c. search()
    d. check()
    Answer: b. findall()geeksforgeeks​
  21. Which regular expression matches strings containing at least two consecutive ‘b’s?
    a. b{2,}
    b. bb
    c. (bb)+
    d. All of the above
    Answer: d. All of the abovelearn.microsoft​
  22. The regular expression (a+b)b(a+b) defines:
    a. Strings where ‘b’ appears at least once
    b. Strings ending with ‘b’
    c. Strings starting with ‘b’
    d. Strings with only ‘a’
    Answer: a. Strings where ‘b’ appears at least oncet4tutorials​
  23. Which operation is not possible using regular expressions?
    a. Backreferencing
    b. Union
    c. Kleene closure
    d. Concatenation
    Answer: a. Backreferencinglearn.microsoft​
  24. In AI chatbot ELIZA, regular expressions were used for:
    a. Parsing user input
    b. Memory management
    c. Network security
    d. System calls
    Answer: a. Parsing user inputcesaraguilar.weebly​
  25. What does the regular expression (xyz)? match?
    a. ‘xyz’ repeated zero or more times
    b. No occurrence or one occurrence of ‘xyz’
    c. Every string containing ‘xyz’
    d. Only empty string
    Answer: b. No occurrence or one occurrence of ‘xyz’learn.microsoft​
  26. Regular expressions can be converted to which type of automata?
    a. Deterministic finite automata (DFA)
    b. Pushdown automata (PDA)
    c. Turing machines
    d. Linear bounded automata
    Answer: a. Deterministic finite automata (DFA)sanfoundry​
  27. The regular expression (a|b)* matches:
    a. Any string over {a, b}
    b. Only strings with alternating a and b
    c. Only the empty string
    d. Only the string “ab”
    Answer: a. Any string over {a, b}t4tutorials​
  28. Which regular expression matches the string “hello”?
    a. hello
    b. h+e+l+l+o+
    c. .hello.
    d. [hello]
    Answer: a. hellolearn.microsoft​
  29. Which of the following is true regarding regular expressions?
    a. Defines regular languages
    b. Can model context-sensitive languages
    c. Defines context-free languages
    d. Can represent every recursively enumerable language
    Answer: a. Defines regular languagest4tutorials​
  30. The regular expression [0-9]{3} matches what?
    a. At least three digits
    b. Exactly three digits
    c. Three alphabetic characters
    d. Any digit
    Answer: b. Exactly three digitslibrarycarpentry.github​
  31. The “+” operator in regular expressions means:
    a. One or more occurrences of preceding element
    b. Zero or more occurrences
    c. Exactly one occurrence
    d. Match all elements
    Answer: a. One or more occurrences of preceding elementlearn.microsoft​
  32. Which regular expression denotes strings that contain ‘cat’ or ‘dog’?
    a. (cat|dog)
    b. [catdog]
    c. cat&&dog
    d. cat+dog
    Answer: a. (cat|dog) learn.microsoft​
  33. What is the regular expression for all strings not containing ‘ab’?
    a. ((a+b)* – ab)
    b. (a*|b*)
    c. (ba)
    d. (a+b)* without ab
    Answer: d. (a+b)* without ablearn.microsoft​
  34. What does “(abc)*” represent?
    a. Only the empty string
    b. Any number of occurrences of “abc”
    c. Only one “abc”
    d. Strings of a, b, or c
    Answer: b. Any number of occurrences of “abc”learn.microsoft​
  35. Which of these is not a regular language?
    a. Strings with equal number of a’s and b’s
    b. Strings ending in ‘ab’
    c. Strings containing only ‘a’
    d. Strings with only even number of b’s
    Answer: a. Strings with equal number of a’s and b’ssanfoundry​
  36. The regular expression “a?b*” matches:
    a. Zero or one ‘a’, followed by zero or more ‘b’s
    b. At least one ‘a’ and one ‘b’
    c. Only ‘bb’
    d. Only ‘a’
    Answer: a. Zero or one ‘a’, followed by zero or more ‘b’slearn.microsoft​
  37. Which regular expression matches all strings of exactly two characters over {a, b}?
    a. (a+b)(a+b)
    b. (a+b)*
    c. a?b?
    d. a+b+
    Answer: a. (a+b)(a+b)learn.microsoft​
  38. What does the regular expression “^abc” match?
    a. ‘abc’ anywhere in the string
    b. ‘abc’ at the start of the string
    c. ‘abc’ at the end of the string
    d. None of these
    Answer: b. ‘abc’ at the start of the stringlearn.microsoft​
  39. Which regular expression denotes all strings over {0,1} that do not contain ’11’?
    a. (0+1)* – 11
    b. (010)*
    c. (101)*
    d. (0+1)* without 11
    Answer: d. (0+1)* without 11learn.microsoft​
  40. Regular expressions in natural language processing are primarily used for:
    a. Pattern matching
    b. Model training
    c. Data normalization
    d. Feature extraction
    Answer: a. Pattern matchingcliffsnotes​
  41. What is the significance of parentheses in regular expressions?
    a. Precedence and grouping
    b. Repetition
    c. Wildcard matching
    d. Concatenation
    Answer: a. Precedence and groupinglearn.microsoft​
  42. What regular expression matches any string not containing the letter ‘z’?
    a. [^z]*
    b. [z]*
    c. z*
    d. .z.
    Answer: a. [^z]*learn.microsoft​
  43. Which regular expression matches an email address?
    a. [A-Za-z0-9.%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,}
    b. @email
    c. ([email]+)
    d. \d*@\d*
    Answer: a. [A-Za-z0-9.
    %+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,}learn.microsoft​
  44. Which function in JavaScript tests a regular expression against a string?
    a. test()
    b. check()
    c. find()
    d. match()
    Answer: a. test()learn.microsoft​
  45. The regular expression ‘^\d{3,}$’ matches:
    a. Strings with at least 3 digits at the start
    b. Strings with exactly 3 digits
    c. Any digit
    d. Digits in the middle only
    Answer: a. Strings with at least 3 digits at the startlearn.microsoft​
  46. Which regular expression matches strings containing only uppercase letters?
    a. [A-Z]+
    b. [a-zA-Z]
    c. [A-Z]*
    d. [A-Z]{2,}
    Answer: a. [A-Z]+learn.microsoft​
  47. For matching whitespace, the regular expression symbol is:
    a. \s
    b. \w
    c. \d
    d. \t
    Answer: a. \slearn.microsoft​
  48. Which regex matches a string with exactly six word characters?
    a. \w{6}
    b. .{6}
    c. \d{6}
    d. [a-z]{6}
    Answer: a. \w{6}learn.microsoft​
  49. What is the output of re.findall(r'[ab]{2,}’, ‘ccaaaabbabbb’)?
    a. [‘aaaa’, ‘bb’, ‘abbb’]
    b. [‘cc’, ‘aaa’]
    c. [‘ab’]
    d. [‘bbb’]
    Answer: a. [‘aaaa’, ‘bb’, ‘abbb’]geeksforgeeks​
  50. Which regex finds dates in the format DD/MM/YYYY?
    a. \d{2}/\d{2}/\d{4}
    b. fd/mm/yyyy
    c. [date]+
    d. dd/mm/yyyy
    Answer: a. \d{2}/\d{2}/\d{4}learn.microsoft​
  1. https://testbook.com/objective-questions/mcq-on-regular-expression–5eea6a1239140f30f369edc8
  2. https://t4tutorials.com/regular-expressions-mcqs-theory-of-automata/
  3. https://www.sanfoundry.com/automata-theory-mcqs-regular-language-expression-2/
  4. https://www.scribd.com/document/285590186/quiz-3-solution
  5. https://librarycarpentry.github.io/lc-data-intro/instructor/03-quiz.html
  6. https://learn.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference
  7. https://cesaraguilar.weebly.com/uploads/2/7/7/5/2775690/2_jurafsky.pdf
  8. https://www.geeksforgeeks.org/quizzes/python-regex-mcq/
  9. https://www.cliffsnotes.com/study-notes/22549077
  10. https://www.scribd.com/document/798592136/unit-2-mcq
  11. https://samagracs.com/regular-expressions-questions-answers-theory-of-computation/
  12. https://www.studocu.com/in/document/anna-university/theory-of-computation/toccs8501-unit-ii-mcq/10624147
  13. https://stackoverflow.com/questions/17351337/using-regular-expression-to-match-multiple-choice
  14. https://www.geeksforgeeks.org/quizzes/regular-expressions-and-json/
  15. https://testbook.com/objective-questions/mcq-on-algebra-of-regular-expressions–5eea6a1239140f30f369edc9
  16. https://www.scribd.com/presentation/250048092/Regular-Expression-Question-Solution
  17. https://dev.to/fakorededamilola/common-questions-in-regular-expression-4l29
  18. https://www.sanfoundry.com/compilers-questions-answers-regular-expression-1/
  19. https://iotmumbai.bharatividyapeeth.edu/media/pdf/ETI_22618_UT1_Question_Bank_2022-23_080323.pdf
  20. https://www.includehelp.com/linux/regular-expressions-aptitude-questions-and-answers.aspx

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!