File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
src/main/java/com/howtodoinjava/regex Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .howtodoinjava .regex ;
2
+
3
+ import java .util .List ;
4
+ import java .util .regex .*;
5
+
6
+ public class StartsWithEndsWith {
7
+
8
+ public static void main (String [] args ) {
9
+
10
+ List <String > lines = List .of (
11
+ "The cat is cute" ,
12
+ "The category is empty" ,
13
+ "The noncategory is also empty" );
14
+
15
+ Pattern pattern = Pattern .compile ("\\ bcat\\ b" , Pattern .CASE_INSENSITIVE );
16
+
17
+ for (String line : lines ) {
18
+ Matcher matcher = pattern .matcher (line );
19
+ while (matcher .find ()) {
20
+ //System.out.println(STR."Match found: \{matcher.group()}");
21
+ }
22
+ }
23
+
24
+ pattern = Pattern .compile ("\\ b\\ w*cat\\ w*\\ b" );
25
+
26
+ for (String line : lines ) {
27
+ Matcher matcher = pattern .matcher (line );
28
+ while (matcher .find ()) {
29
+ System .out .println (STR ."Match found: \{matcher .group ()}" );
30
+ }
31
+ }
32
+ }
33
+ }
You can’t perform that action at this time.
0 commit comments