A regular expression overview and simple use
Regular expression
Is a single string that describes or matches a series of strings that conform to a syntactic rule. It’s just a rule. It has its own special application.
Function: For example, to register a mailbox, the mailbox has a user name and password, generally will limit its length, this limit length is the regular expression to do
Case presentation
Requirement: verify QQ number.
1: The number must be 5-15 digits
Two zero cannot begin
3: They must all be numbers
A: Non-regular expression implementation
B: Regular expression implementation
Second, the character class demo
Character classes
[ABC] a, B or C (simple class)
[^ ABC] any character except a, B, or C (negative)
[a-za-z] a to Z or a to Z, inclusive (range)
[0-9] Contains all characters from 0 to 9
Three, predefined character class demonstration
Predefined character class
.Any character.
\ D Digital: [0-9]
\ W Word characters: [A-za-z_0-9]
Quantifiers
Greedy quantifiers
X? X, not once or not
X times X, zero or more times
X plus X, one or more times
X{n} X, exactly n times
X{n,} X, at least n times
X{n,m} X, at least n times, but no more than m times
5. Regular expression segmentation function
Regular expression segmentation function
Public String[] split(String regex)
Case presentation
Regular expression segmentation function
The replacement function of regular expressions
Regular expression replacement function
Public String replaceAll(String regex,String replacement)
Case presentation
Regular expression replacement function
The grouping function of regular expressions
The grouping function of regular expressions
Capture groups can be numbered by counting their open brackets from left to right. For example, in the expression ((A)(B(C)), there are four groups like this:
1 ((A)(B(C)))
2 (A
3 (B(C))
4 (C)
The group zero always represents the entire expression.
Case presentation
A: cutting
Demand: please cut according to the refrain: “SDQQFGKKKHJPPPPKL “;
B: replace
Needs: I I…. I… I want to… Want to… Want to learn… Learn.. Learn. Make up.. Make up. Make up. Make up. Cheng.. cheng
Restore the string to: “I want to learn to program.”
An overview of Pattern and Matcher
A: An overview of Pattern and Matcher
B: Typical call order for patterns and matchers
View the description of the Pattern class using the API provided by the JDK
The typical call sequence is
Pattern p = Pattern.compile(“a*b”);
Matcher m = p.matcher(“aaaaab”);
boolean b = m.matches();
Nine, regular expression to obtain the function
Get regular expressions
A combination of Pattern and Matcher
Case presentation
Need: get the phone number from a string
An overview of the Math class and method usage
Summary of Math class
The Math class contains methods for performing basic mathematical operations, such as exponentials, logarithms, square roots, and trigonometric functions.
Members of the method
public static int abs(int a)
public static double ceil(double a)
public static double floor(double a)
Public static int Max (int a,int b) min
public static double pow(double a,double b)
public static double random()
Public static int round(float a) public static int round(float a
public static double sqrt(double a)
Overview of Random class and method usage
An overview of the Random class
This class is used to generate Random numbers. If two Random instances are created using the same seed,
The same sequence of method calls is applied to each instance, and they generate and return the same sequence of numbers.
A constructor
public Random()
public Random(long seed)
Members of the method
public int nextInt()
Public int nextInt(int n)
Overview of the System class and method usage
An overview of the System class
The System class contains some useful class fields and methods. It cannot be instantiated.
Members of the method
public static void gc()
public static void exit(int status)
public static long currentTimeMillis()
pubiic static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
Case presentation
Member methods of the System class
BigInteger class overview and method usage
An overview of BigInteger
Data beyond the Integer range can be manipulated
A constructor
public BigInteger(String val)
Members of the method
public BigInteger add(BigInteger val)
public BigInteger subtract(BigInteger val)
public BigInteger multiply(BigInteger val)
public BigInteger divide(BigInteger val)
public BigInteger[] divideAndRemainder(BigInteger val)
An overview of the BigDecimal class and method use
BigDecimal overview of
Since float and double are easy to lose precision during operations, this is an example.
Therefore, Java provides BigDecimal in order to accurately represent and evaluate floating point numbers
An immutable, arbitrary precision signed decimal number.
A constructor
public BigDecimal(String val)
Members of the method
public BigDecimal add(BigDecimal augend)
public BigDecimal subtract(BigDecimal subtrahend)
public BigDecimal multiply(BigDecimal multiplicand)
public BigDecimal divide(BigDecimal divisor)
Date class overview and method use
An overview of the Date class
The Date class represents a specific moment, down to the millisecond.
A constructor
public Date()
public Date(long date)
Members of the method
public long getTime()
public void setTime(long time)
The SimpleDateFormat class converts dates to strings
Overview of the DateFormat class
DateFormat is an abstract class of a date/time formatting subclass that formats and parses dates or times in a language-independent manner. SimpleDateFormat is abstract, so use its subclass SimpleDateFormat
SimpleDateFormat constructor
public SimpleDateFormat()
public SimpleDateFormat(String pattern)
Members of the method
public final String format(Date date)
public Date parse(String source)
An overview of the Calendar class and methods for getting dates
An overview of the Calendar class
The Calendar class is an abstract class that provides methods for converting between a specific moment and a set of Calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR, and so on, as well as methods for manipulating Calendar fields, such as getting the next week’s date.
Members of the method
public static Calendar getInstance()
public int get(int field)
Calendar class add() and set() methods
Members of the method
public void add(int field,int amount)
public final void set(int year,int month,int date)
Case presentation
Member methods of the Calendar class