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

Example Analysis of java regular expressions getting the contents of curly braces and judging numbers and decimals

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Editor to share with you about the java regular expression to get curly braces and determine the contents of braces and decimals of the example analysis, I believe that most people do not understand, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!

Get curly braces and parentheses contents

The project development has been used, so make a simple record for the time being.

Private static String regex = "\ {([^}] *)\\}"; / / matching curly braces private static String regexx = "\\ (([^}] *)\\)"; / / matching parentheses public static void main (String [] args) {String dakuohao = "{aquib} = {cantid} > {d}"; Pattern compile = Pattern.compile (regex); Matcher matcher = compile.matcher (dakuohao); while (matcher.find ()) {String group = matcher.group (); System.out.print (group+ ") ");} System.out.println (); String xiaokuohao =" (aqb) = (Centrd) > (d) "; Pattern comp = Pattern.compile (regex); Matcher mat = comp.matcher (dakuohao); while (mat.find ()) {String group = mat.group (); System.out.print (group+"; ");}}

For expressions that match curly braces and parentheses, only the symbol after the escape has changed, can it be replaced with something else?

What about symmetrical symbols?

Judge whether a number is a decimal or a decimal mixture

Integer ^ ([0-9] {1,} [.] [0-9] *) $

Decimal ^ ([0-9] {1,} [.] [0-9] *) $

I also found a lot of blogs during the test, and I felt that most people could not avoid the special symbols in the numbers.

Decimal and number mix (^ [0-9] * $) | (^ ([0-9] {1,} [.] [0-9] *) $)

Ps:java uses regular expressions to extract the contents of parentheses

Public class Test {public static List getMsg (String msg) {List list = new ArrayList (); Pattern p = Pattern.compile ("(\\ () ([0-9a-zA-Z\.\\ /\ =]) * (\); Matcher m = p.matcher (msg); while (m.find ()) {list.add (m.group (0) .substring (1, m.group (). Length ()-1);} return list } public static void main (String [] args) throws Exception {String msg = "mSurface=Surface (name=com.bbk.launcher2/com.bbk.launcher2.Launcher)"; List list = getMsg (msg); System.out.println (list);}} above is all the contents of the article "java regular expressions get the contents of curly braces and determine the sample analysis of numbers and decimals". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to 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

Internet Technology

Wechat

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

12
Report