xgqfrms / java

java playground :shit: :cloud: 👻
https://java.xgqfrms.xyz
2 stars 0 forks source link

java & repl #1

Open xyzdata opened 6 years ago

xyzdata commented 6 years ago

java & repl

https://www.tutorialspoint.com/compile_java_online.php

Regex


import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexMatches {
   public static void main( String args[] ) {
        String test = "config/${RunMod}/opration/server-config.xml/${RunMod}/";
        // test = test.replaceAll("\\$\\{\\w*\\}", "debug");
        // System.out.println(test);
        // String abc = "config/${RunMod}/opration/server-config.xml/${RunMod}/";
        // abc = abc.quoteReplacement("");
        // System.out.println(abc);
        // Pattern p = Pattern.compile("\\$\\{\\w*\\}");
        // Matcher m = p.matcher(test);
        // System.out.println("lookingAt(): "+ m.lookingAt());
        String content = "Let's find the symbols or currencies : ${Dollar}, ${xxx},€ Euro, ¥ Yen";
        String regex = "\\$\\{\\w*\\}";
        // String regex = "\\p{Sc}";
        // Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(content);
        while (matcher.find()) {
            System.out.print("Start index: " + matcher.start());
            System.out.print(" End index: " + matcher.end() + " ");
            System.out.println(" : " + matcher.group());
            String abc = matcher.group();
            System.out.println("abc = " + abc);
            abc = abc.replaceAll("\\$", "").replaceAll("\\{", "").replaceAll("\\}", "");
            System.out.println(abc);
            String result = "";
            switch(abc){
                case "Dollar":
                    result = test.replaceAll("\\$\\{\\w*\\}", "debug");
                    break;
                case "xxx":
                    result = test.replaceAll("\\$\\{\\w*\\}", "yyy");
                    break;
                default:
                    break;
            }
            System.out.println(test);
            System.out.println(result);
        }
   }
}
xyzdata commented 6 years ago

RegExp

https://regexper.com/#%2F%5E%5C%24%5C%7B%28%5Cw%2B%29%5C%7D%24%2F

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp

/^\$\{(\w+)\}$/

// source
// config/${RunMod}/opration/server-config.xml  

// wanted result
//config/debug/opration/server-config.xml  

let str = "config/${RunMod}/opration/server-config.xml, config/${RunMod}/opration/server-config.xml"

str.replace(/\$\{(\w+)\}/ig, "debug");

image

xyzdata commented 6 years ago

java & regex

https://howtodoinjava.com/regex/java-regex-match-any-currency-symbol/

https://docs.oracle.com/javase/6/docs/api/java/lang/String.html https://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html#sum

https://docs.oracle.com/javase/specs/#100850


https://stackoverflow.com/questions/610333/how-to-replace-a-plus-character-using-javas-string-replaceall-method

https://javamex.com/tutorials/regular_expressions/search_replace.shtml#.Wt2iMohubIU https://howtodoinjava.com/regex/java-regex-match-any-currency-symbol/

https://stackoverflow.com/questions/9716443/how-to-escape-dollar-sign-in-a-string-using-perl-regex http://www.tutorialspoint.com/java/java_regular_expressions.htm

repl

https://www.tutorialspoint.com/compile_java_online.php https://repl.it/repls/AlphanumericPolishedGraphics

http://www.regexplanet.com/advanced/java/index.html https://www.freeformatter.com/java-regex-tester.html

xyzdata commented 6 years ago

https://www.tutorialspoint.com/tpcg.php?p=KqpMl5

http://tpcg.io/KqpMl5