FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
OnJava8-Examples/strings/Groups.java at master · CSapprenticeWT/OnJava8-Examples · GitHub
CSapprenticeWT
OnJava8-Examples
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
OnJava8-Examples
/
strings
/
Groups.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
40 lines (39 loc) · 1.35 KB
Breadcrumbs
OnJava8-Examples
/
strings
/
Groups.java
Copy path
File metadata and controls
40 lines (39 loc) · 1.35 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// strings/Groups.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import
java
.
util
.
regex
.*;
public
class
Groups
{
public
static
final
String
POEM
=
"Twas brillig, and the slithy toves
\n
"
+
"Did gyre and gimble in the wabe.
\n
"
+
"All mimsy were the borogoves,
\n
"
+
"And the mome raths outgrabe.
\n
\n
"
+
"Beware the Jabberwock, my son,
\n
"
+
"The jaws that bite, the claws that catch.
\n
"
+
"Beware the Jubjub bird, and shun
\n
"
+
"The frumious Bandersnatch."
;
public
static
void
main
(
String
[]
args
) {
Matcher
m
=
Pattern
.
compile
(
"(?m)(
\\
S+)
\\
s+((
\\
S+)
\\
s+(
\\
S+))$"
)
.
matcher
(
POEM
);
while
(
m
.
find
()) {
for
(
int
j
=
0
;
j
<=
m
.
groupCount
();
j
++)
System
.
out
.
print
(
"["
+
m
.
group
(
j
) +
"]"
);
System
.
out
.
println
();
}
}
}
/* Output:
[the slithy toves][the][slithy toves][slithy][toves]
[in the wabe.][in][the wabe.][the][wabe.]
[were the borogoves,][were][the
borogoves,][the][borogoves,]
[mome raths outgrabe.][mome][raths
outgrabe.][raths][outgrabe.]
[Jabberwock, my son,][Jabberwock,][my son,][my][son,]
[claws that catch.][claws][that catch.][that][catch.]
[bird, and shun][bird,][and shun][and][shun]
[The frumious Bandersnatch.][The][frumious
Bandersnatch.][frumious][Bandersnatch.]
*/
Back
|
FazBrowse Home
|
New Git URL