Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

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

Shulou Source: shulou.com Published: 2022-06-02 13:38:37 10月03日 Update

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!

Tags: Parentheses content decimals numbers expressions regularities symbols articles examples analysis mixing special symmetrical not much blog only most feeling integer time Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Redmi MariaDB Xiaomi Microsoft