Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Sample Analysis of regular Operation of JavaString Class

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report