Skip to content

Commit a0acb4d

Browse files
committed
Regex
1 parent e89ed35 commit a0acb4d

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

Readme.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,13 @@ public class Test extends PreTest {
109109

110110
}
111111

112-
/*---- NOTE: Always pay attention to new Test() or the new Class(), it will tell you which class
113-
that object is going to create an image of, then no matter which class' object reference it has,
114-
it is only going to have methods of the class mentioned with new keyword ----*/
115-
116-
117-
/*-- PreTest obj = new Test(); (Then blue print of Test Class will be created) --*/
118112

119113
```
120114

115+
> NOTE: (Require correction) Always pay attention to new Test() or the new Class(), it will tell you which class
116+
that object is going to create an image of, then no matter which class' object reference it has,
117+
it is only going to have methods of the class mentioned with new keyword.
118+
121119
## *Comparators in Java:*
122120

123121
```java
@@ -287,3 +285,22 @@ public class Test{
287285

288286
}
289287
```
288+
289+
## *Regular Expressions in Java:*
290+
291+
292+
| SN | Regular Expression | Description
293+
| :----: | :---: | :---:
294+
| 1 | `[A-Za-z]` | It matches all the uppercase and lowercase characters
295+
| 2 | `[-+.^:,]` | It matches all the special characters
296+
| 3 | `[.]` | It matches with a character of any kind
297+
298+
299+
## *Lambdas in Java programming:*
300+
301+
*Printing with characters with the help of Java Stream:*
302+
303+
```java
304+
int[] arr = {1,2,3,4,5,6,7,8,9};
305+
Arrays.stream(arr).map(i->i*i).forEach(System.out::println);
306+
```

Topics/JavaRegex2.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import java.util.regex.Pattern;
44

55

6-
/* Problem statement:
7-
* Validating a phone number BAA-AAA-AAAA using regular expression in Java..
6+
/* Problem statement:
7+
* Validating a phone number BAA-AAA-AAAA using regular expression in Java..
88
* ..where A is a digit ranging 0-9 and B is also a digit ranging 1-9
99
*/
1010

@@ -14,30 +14,27 @@
1414
* \\w - Any alphanumeric character
1515
* \\. - Dot character
1616
* + - More than one character
17-
* [1-9] - Any digit between 1 to 9
17+
* [1-9] - Any digit between 1 to 9
1818
*/
1919

2020
public class JavaRegex2 {
2121

2222
public static void main(String[] args) {
23-
24-
Scanner sc = new Scanner(System.in);
23+
24+
Scanner sc = new Scanner(System.in);
2525
String email = sc.next();
26-
27-
Pattern p = Pattern.compile("^[1-9]\\d{2}-\\d{3}-\\d{4}$");
26+
27+
Pattern p = Pattern.compile("^[1-9]\\d{2}-\\d{3}-\\d{4}$");
2828

2929
Matcher matcher = p.matcher(email);
30-
30+
3131
if(matcher.find()){
3232
System.out.println("This is a valid phone number");
3333
}
34-
34+
3535
else
3636
System.out.println("This is not a valid phone number");
3737

3838
}
3939

4040
}
41-
42-
43-

0 commit comments

Comments
 (0)