Java regular replacement mobile phone number code example

In our daily life, we often encounter replacing the 4-7 bit string of a mobile phone number with an asterisk "*" with a regular expression. This is because of the consideration of security and protecting customer privacy. Let's take a look at the specific code.

The output results are as follows:

This is just a simple usage of regular expressions. Let's expand other related usage and specific introduction.

1. Simple matching @ h_ 419_ 17@

In Java, strings can be used directly

Note: regular expressions match all strings @ H_ 419_ 17@

2. Match and find @ h_ 419_ 17@

Find the substring that matches the regular expression in the string, and take out the value in angle brackets in combination with the following example of pattern matcher

At this time, you can also find multiple matching groups. You need to add brackets in the regular expression. One bracket corresponds to one group

3. Find and replace, use of placeholders

Replace a before a or D with *, and $is the placeholder in the regular expression.

Summary:

The above is the specific code of replacing the middle four digits of mobile phone number with regular expression and some related usage of regular expression in this paper. I hope it will be helpful to you.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>