java regular expression summary

Regular expression with String

Regular expression replacement with String

Regular expression split by String

Regular expression matching by String

System.out.println ("not E-mail"); } }

Comparison of String regular expression and (Pattern, Matcher) regular expression

String and pattern

private static void textPattern() {

//文字列 String string = "da646dad4da64da54d6a4d5a4d6a4d5ae78w"; String regex = "[0-9]+"; // Divide by pattern Pattern pattern = Pattern.compile(regex); System.out.println(Arrays.toString(pattern.split(string))); // Divide by string System.out.println(Arrays.toString(string.split(regex))); } // Result [da, dad, da, da, d, a, d, a, d, a, d, ae, w]    [da, dad, da, da, d, a, d, a, d, a, d, ae, w]

String and matcher

private static void testMatcher() {
	String str = "2019-09-10";
	String regex = "\\d{4}\\-\\d{2}\\-\\d{2}";

// Matching by Matcher Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(str); System.out.println(""+ matcher.matches()); // Matching by String System.out.println(""+str.matches(regex)); } // Result true true

Summary of frequently used regular expressions

One letter

regex meaning Remarks
abc abc
\\n new line
\\t tab
[abc] a or b or c
[^abc] a,b,Other than c
[a-zA-Z] Alphabet
[a-d[m-p]] a-d or m-p
\\d Numbers
\\D Other than numbers
\\w a-z A-With Z_ [a-zA-Z_]Same as
\\W Other than those above

Many characters

regex meaning Remarks
\\d+ One or more numbers
\\d? Number 0 1
\\d* Number 0, 1 or more
\\d{5} 5 numbers
\\d{5,10} Numbers 5 or more and 10 or less
\\d{5,} 5 or more numbers

Numerous judgments

regex meaning Remarks
XY Judgment X followed by Y
X|Y Judgment X or Y
(X) Group Judgment X

Sample code

Recommended Posts

java regular expression summary
[Java] Summary of regular expressions
Java knowledge summary
Java Generics Summary
Java 8 documentation summary
[Java] Lambda expression
Regular expression basics
JS regular expression
Java 11 document summary
Ruby regular expression
Java lambda expression
Ruby: Regular expression summary * Code sample available
Java 12 new feature summary
[Summary] Java environment preparation
effective java 3rd summary
Java 13 new feature summary
java learning (conditional expression)
java neutral lambda expression 1
Java lambda expression variations
Java static [Personal summary]
^, $ in Rails regular expression
Java 8 lambda expression Feature
java lambda expression memo
Thread safe summary ~ Java ~
unicode regular expression sample
Java Primitive Specialization Summary
Java development link summary
Personal summary about Java
Java lambda expression [memo]
Regular expression for password
Studying Java 8 (lambda expression)
Review java8 ~ Lambda expression ~
Java lambda expression again
Java table expression injection
Java 10 new feature summary
Java 14 new feature summary
Summary of Java support 2018
Java design pattern summary
Java reserved word summary
Java8 Stream Rough Summary
What is Java Assertion? Summary.
[Java] Functional interface / lambda expression
[Java11] Stream Summary -Advantages of Stream-
[Java] Summary of operators (operator)
Object-oriented summary by beginners (Java)
Full-width / half-width judgment regular expression
Summary of Java language basics
Java tips --Spring execution Summary
[Java] Summary of for statements
Summary of Java Math class
[Java11] Stream Usage Summary -Basics-
[Java] Summary of control syntax
Summary of java error processing
[Java] Summary of design patterns
[Java] Summary of mathematical operations
Consideration on Java Persistence Framework 2017 (Summary) -1
[For beginners] Summary of java constructor
Java release date and EOL summary
Summary of [Java silver study] package
Java basic learning content 9 (lambda expression)
Summary