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 Specific Characters
  • Excluding Specific Characters
  • Matching Character Ranges

Was this helpful?

  1. Regex

Character Class

PreviousIntroductionNextRepetitions

Last updated 1 year ago

Was this helpful?

Matching Specific Characters

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

  • S must be of length: 6

  • First character: 1, 2 or 3

  • Second character: 1, 2 or 0

  • Third character: x, s or 0

  • Fourth character: 3, 0 , A or a

  • Fifth character: x, s or u

  • Sixth character: . or ,

^[1-3][120][xs0][30Aa][xsu][\.,]$

Excluding Specific Characters

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

  • S must be of length 6.

  • First character should not be a digit (1, 2, 3, 4, 5, 6, 7, 8, 9 or 0).

  • Second character should not be a lowercase vowel (a, e, i, o or u).

  • Third character should not be b, c, D or F.

  • Fourth character should not be a whitespace character ( \r, \n, \t, \f or <space> ).

  • Fifth character should not be a uppercase vowel (A, E, I, O or U).

  • Sixth character should not be a . or , symbol.

^[^\d][^aeiou][^bcDF][^\s][^AEIOU][^\.,]$

Matching Character Ranges

Write a RegEx that will match a string satisfying the following conditions:

  • The string’s length is >= 5.

  • The first character must be a lowercase English alphabetic character.

  • The second character must be a positive digit. Note that we consider zero to be neither positive nor negative.

  • The third character must not be a lowercase English alphabetic character.

  • The fourth character must not be an uppercase English alphabetic character.

  • The fifth character must be an uppercase English alphabetic character.

^[a-z][1-9][^a-z][^A-Z][A-Z]
Solve Programming Questions | HackerRankHackerRank
Logo