Get the App
SLTechnology News&Howtos  ›  Development  › 

Sample Analysis of regular Operation of JavaString Class

Shulou Source: shulou.com Published: 2022-06-03 05:58:32 09月26日 Update

This article is to share with you about the JavaString class regular operation example analysis, the editor feels very practical, so share with you to learn, I hope you can get something after reading this article, say no more, follow the editor to have a look.

First, apply regular expressions

1 code

Public class RegExp {public static void main (String [] args) throws Exception {if ("123" .numbers ("\\ d +")) {System.out.println ("made up of numbers!") ;} else {System.out.println ("not composed of numbers!") ;}

2 run

It's made up of numbers!

Two string substitution-filter the numbers in the string

1 code

Public class SubString {public static void main (String [] args) throws Exception {String str = "a1b22c333d4444e55555f6666666g"; String regex = "[0-9] +"; / / numbers appear one or more times / / String regex = "\\ d +"; / / numbers appear one or more times System.out.println (str.replaceAll (regex, "));}}

2 run

Abcdefg

Three regularities verify mailbox format

1 code

Import java.util.*;public class EmailValidation {public static void main (String [] args) throws Exception {String str = null; String regex = "\\ wicked @\ wicked.\\ w+"; Scanner reader = new Scanner (System.in); do {System.out.print ("Please enter a valid email address:"); str = reader.next (); System.out.println (str);} while (! str.matches (regex)); System.out.println ("email address is valid! Thank you for registering! ") ; reader.close ();}}

2 run

Please enter a valid email address: April to April. Please enter a valid email address: yy@qq.comyy@qq.com email address is valid! Thank you for registering!

The above is the JavaString class regular operation example analysis, the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Tags: Number valid address email regular code input run example analysis character string more knowledge article practical that is work meeting article is made up of Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn OPPO Reno MariaDB Redmi Shulou Technology