Commonly asked Data Structures and Algorithms Problems by big tech and different solution approaches with code in Java and C

Powered by Blogger.

Tuesday, August 8, 2017

REGEX


mathces() check whether pattern matches with whole string and find() check for a occurrence of pattern in that string.

Pattern to check for String hackerrank

 tester.checker("[h][a][c][k][e][r][r][a][n][k]");

Pattern to check for String abc.abc.abc.abc
. Represent everything except new line

tester.check("(.{3}[.]){3}(.{3})");

Pattern to check for String xxXxxXxxxx
where x is number and X is non numeric

  tester.checker("((\\d){2}(\\D)){2}((\\d){4})");

\\s is used to check white space and \\S to check except white space
To represent 12 11 15

(\\S{2}\\s){2}\\S{2}

\\w is used to represent word
$ is used to represent end of string and ^ to start position of string
Ex:
0qwer.
"^[\\d][\\w]{4}.$"

string starts with 1/2/3 and ends with ./, having middle 4 chars as specified

"^[123][120][xs0][30Aa][xsu][.,]$"


To handle confusion in ^
problem: https://www.hackerrank.com/challenges/excluding-specific-characters?h_r=next-challenge&h_v=zen

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

0 Comments:

Post a Comment

Stats