Replacing Text

Discussion in 'Spigot Plugin Development' started by RedNinjaPlaysMC, Jun 2, 2016.

  1. Someone types this in chat: "<websitename>.net". I want to replace the whole thing. But right now, I only know how to replace the .net part. How do you replace <websitename>?

    Here is my code so far:
    Code (Text):
    @EventHandler
        public void sendChatMessage(AsyncPlayerChatEvent e)
        {
            String newMessage = e.getMessage().replace(".net", "*")
        }
     
  2. I do it like so >>

    Code (Text):
    Pattern webPattern = Pattern.compile("(http://)|(https://)?(www)?\\S{2,}((\\.com)|(\\.ru)|(\\.net)|(\\.org)|(\\.co\\.uk)|(\\.fr)|(\\.tk)|(\\.info)|(\\.me)|(\\.es)|(\\.de)|(\\.arpa)|(\\.edu)|(\\.firm)|(\\.int)|(\\.mil)|(\\.mobi)|(\\.nato)|(\\.to)|(\\.fr)|(\\.ms)|(\\.vu)|(\\.eu)|(\\.nl)|(\\.ch)|(\\.us)|(\\.dk))", Pattern.CASE_INSENSITIVE);

     Matcher matcher = webPattern.matcher(e.getMessage());

    while(matcher.find()) {  
        Than you can do it e.setCan...    
    }
     
  3. what does the pattern do?
     
  4. @RedNinjaPlaysMC look up regular expressions. It allows you to find text using a pattern.
     
  5. I want to replace the minecraft.net and change it to a "*"
     
  6. Yeah and what is the Problem. You find sth. and than you replacing e.getMessage() ?
     
  7. Im also trying to replace "minecraft", not just ".net"
     
  8. @RedNinjaPlaysMC I just noticed your impatience. This isn't going to get you any further. I was thinking of giving you a small sample, but now you can just google it yourself. Something like "Java regular expression replace" should do
     
    • Agree Agree x 1