Skip to content

Commit 45e2e6f

Browse files
committed
Docs update
1 parent e731df7 commit 45e2e6f

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

docs/Regular Expressions.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
1+
# Regular Expression
2+
3+
## What it is?
4+
- It's pattern matching language used to find and extract text
5+
- for example to find/match all dates in text we can use `\d{4}-\d{2}-\d{2}` format to match Data: YYYY-MM-DD pattern
6+
- Use Case
7+
- Check validity fo user input
8+
- like if user given input is valid email id, licensekey)
9+
- If given data contain specific info like string contain numbers or symbols
10+
- Data extraction using pattern matching
11+
12+
## How to use it?
13+
- Use [Regexr](https://regexr.com/) website for testing
14+
- Here is sample code to find all numbers from string
15+
- If we only use `\d` it will print individual number separately like `4,2,5,0,0,9,9,9`
16+
- That extra `+` sign allows whole number till next space
17+
18+
```csharp
19+
string text = "My numbers are 42, 500 and 999";
20+
string pattern = @"\d+";
21+
22+
MatchCollection matches = Regex.Matches(text, pattern);
23+
24+
foreach (Match m in matches)
25+
{
26+
Console.WriteLine(m.Value);
27+
}
28+
```
29+
```
30+
42
31+
500
32+
999
33+
```
34+
35+
36+
## Pattern
37+
138
```
239
. - Any Character Except New Line
340
\d - Digit (0-9)

0 commit comments

Comments
 (0)