Character classes और repetitions

R में Intermediate Regular Expressions

Angelo Zehr

Data Journalist

उपलब्ध character classes

Character Class उदाहरण
\\d or [:digit:] 0, 1, 2, 3,…
\\w or [:word:] a, b, c…, 1, 2, 3…, _
[A-Za-z] or [:alpha:] A, B, C,…, a, b, c,…
[aeiou] a, e, i, o या u में से कोई एक
\\s or [:space:] " ", tabs या line breaks
R में Intermediate Regular Expressions

एक ठोस उदाहरण

str_match_all() परिणाम
"Hi John_35", "\\d" "3", "5"
"Hi John_35", "\\w" "H", "i", "J", "o", "h", "n", "_", "3", "5"
"Hi John_35", "[A-Za-z]" "H", "i", "J", "o", "h", "n"
"Hi John_35", "[aeiou]" "i", "o"
"Hi John_35", "\\s" " "
R में Intermediate Regular Expressions

Repetitions

सिंटैक्स अर्थ
\\w{2} ठीक 2 बार
\\w{2,3} न्यूनतम 2 बार, अधिकतम 3 बार
\\w{2,} न्यूनतम 2 बार, कोई अधिकतम नहीं
\\w+ 1 या अधिक repetitions
\\w* 0, 1 या अधिक repetitions
R में Intermediate Regular Expressions

Character classes का inversion

मूल निषेध
\\d digits से match \\D digits को छोड़कर बाकी सब से match
\\w word characters से match \\W word characters को छोड़कर बाकी सब से match
\\s spaces से match \\S spaces को छोड़कर बाकी सब से match
[a-zA-Z] alphabet से match [^a-zA-Z] alphabet को छोड़कर बाकी सब से match
R में Intermediate Regular Expressions

क्लासेस के साथ कस्टम पैटर्न

str_match_all("Toy Story 3", "[\\d\\s]")

परिणाम:

     [,1]
[1,] " " 
[2,] " " 
[3,] "3"
R में Intermediate Regular Expressions

अभ्यास करते हैं!

R में Intermediate Regular Expressions

Preparing Video For Download...