Thamizhiniyan C S
HomeWriteupsResourcesCheatsheets
HackerRank
HackerRank
  • HackerRank
  • Linux Shell
    • Bash
    • Text Processing
      • Cut
      • Head
      • Middle
      • Tail
      • Tr
      • Sort
      • Uniq
      • Paste
    • Arrays In Bash
    • Grep Sed Awk
      • Grep
      • Sed
      • Awk
  • Regex
    • Introduction
    • Character Class
    • Repetitions
    • Grouping and Capturing
    • Backreferences
    • Assertions
    • Applications
  • Python
    • Introduction
    • Basic Data Types
    • Strings
    • Sets
    • Math
    • Itertools
    • Collections
    • Date and Time
    • Errors and Exceptions
    • Classes
    • Built-Ins
    • Python Functionals
    • Regex and Parsing
    • XML
    • Closures and Decorators
    • Numpy
    • Debugging
  • C
    • Introduction
    • Conditionals and Loops
    • Arrays and Strings
Powered by GitBook
On this page
  • Matching {x} Repititions
  • Matching {x, y} Repititions
  • Matching Zero Or More Repititions
  • Matching One Or More Repititions
  • Matching Ending Items

Was this helpful?

  1. Regex

Repetitions

PreviousCharacter ClassNextGrouping and Capturing

Last updated 1 year ago

Was this helpful?

Matching {x} Repititions

You have a test string S. Your task is to write a regex that will match S using the following conditions:

  • S must be of length equal to 45.

  • The first 40 characters should consist of letters(both lowercase and uppercase), or of even digits.

  • The last 5 characters should consist of odd digits or whitespace characters.

^[a-zA-z02468]{40}[13579\s]{5}$

Matching {x, y} Repititions

You have a test string S. Your task is to write a regex that will match S using the following conditions:

  • S should begin with 1 or 2 digits.

  • After that, S should have 3 or more letters (both lowercase and uppercase).

  • Then S should end with up to 3. symbol(s). You can end with 0 to 3. symbol(s), inclusively.

^\d{1,2}[a-zA-Z]{3,}\.{,3}$

Matching Zero Or More Repititions

You have a test string S. Your task is to write a regex that will match S using the following conditions:

  • S should begin with 2 or more digits.

  • After that, S should have 0 or more lowercase letters.

  • S should end with 0 or more uppercase letters

^\d{2,}[a-z][A-Z]$

Matching One Or More Repititions

You have a test string S. Your task is to write a regex that will match S using the following conditions:

  • S should begin with 1 or more digits.

  • After that, S should have 1 or more uppercase letters.

  • S should end with 1 or more lowercase letters.

^\d+[A-Z]+[a-z]+$

Matching Ending Items

Write a RegEx to match a test string, S, under the following conditions:

  • S should consist of only lowercase and uppercase letters (no numbers or symbols).

  • S should end in s.

^[a-zA-Z]*s$
Solve Programming Questions | HackerRankHackerRank
Logo