Class Parser


  • public final class Parser
    extends java.lang.Object
    Avoid using regex !!!
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Parser.RegexException  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Map<java.lang.String,​java.lang.String> compatParseMap​(java.lang.String input)  
      static boolean isMatch​(java.lang.String pattern, java.lang.String input)  
      static boolean isMatch​(java.util.regex.Pattern pattern, java.lang.String input)  
      static java.lang.String matchGroup​(java.lang.String pattern, java.lang.String input, int group)
      Matches the specified group of the given pattern against the input, and returns the matched group
      static java.lang.String matchGroup​(java.util.regex.Pattern pattern, java.lang.String input, int group)
      Matches the specified group of the given pattern against the input, and returns the matched group
      static java.lang.String matchGroup1​(java.lang.String pattern, java.lang.String input)
      Matches group 1 of the given pattern against the input and returns the matched group
      static java.lang.String matchGroup1​(java.util.regex.Pattern pattern, java.lang.String input)
      Matches group 1 of the given pattern against the input and returns the matched group
      static java.lang.String matchGroup1MultiplePatterns​(java.util.regex.Pattern[] patterns, java.lang.String input)
      Matches multiple patterns against the input string and returns the first successful matcher
      static java.util.regex.Matcher matchMultiplePatterns​(java.util.regex.Pattern[] patterns, java.lang.String input)
      Matches multiple patterns against the input string and returns the first successful matcher
      static java.util.regex.Matcher matchOrThrow​(java.util.regex.Pattern pattern, java.lang.String input)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • matchGroup1

        @Nonnull
        public static java.lang.String matchGroup1​(java.lang.String pattern,
                                                   java.lang.String input)
                                            throws Parser.RegexException
        Matches group 1 of the given pattern against the input and returns the matched group
        Parameters:
        pattern - The regex pattern to match.
        input - The input string to match against.
        Returns:
        The matching group as a string.
        Throws:
        Parser.RegexException - If the pattern does not match the input or if the group is not found.
      • matchGroup1

        @Nonnull
        public static java.lang.String matchGroup1​(java.util.regex.Pattern pattern,
                                                   java.lang.String input)
                                            throws Parser.RegexException
        Matches group 1 of the given pattern against the input and returns the matched group
        Parameters:
        pattern - The regex pattern to match.
        input - The input string to match against.
        Returns:
        The matching group as a string.
        Throws:
        Parser.RegexException - If the pattern does not match the input or if the group is not found.
      • matchGroup

        @Nonnull
        public static java.lang.String matchGroup​(java.lang.String pattern,
                                                  java.lang.String input,
                                                  int group)
                                           throws Parser.RegexException
        Matches the specified group of the given pattern against the input, and returns the matched group
        Parameters:
        pattern - The regex pattern to match.
        input - The input string to match against.
        group - The group number to retrieve (1-based index).
        Returns:
        The matching group as a string.
        Throws:
        Parser.RegexException - If the pattern does not match the input or if the group is not found.
      • matchGroup

        @Nonnull
        public static java.lang.String matchGroup​(@Nonnull
                                                  java.util.regex.Pattern pattern,
                                                  java.lang.String input,
                                                  int group)
                                           throws Parser.RegexException
        Matches the specified group of the given pattern against the input, and returns the matched group
        Parameters:
        pattern - The regex pattern to match.
        input - The input string to match against.
        group - The group number to retrieve (1-based index).
        Returns:
        The matching group as a string.
        Throws:
        Parser.RegexException - If the pattern does not match the input or if the group is not found.
      • matchGroup1MultiplePatterns

        public static java.lang.String matchGroup1MultiplePatterns​(java.util.regex.Pattern[] patterns,
                                                                   java.lang.String input)
                                                            throws Parser.RegexException
        Matches multiple patterns against the input string and returns the first successful matcher
        Parameters:
        patterns - The array of regex patterns to match.
        input - The input string to match against.
        Returns:
        A Matcher for the first successful match.
        Throws:
        Parser.RegexException - If no patterns match the input or if patterns is empty.
      • matchMultiplePatterns

        public static java.util.regex.Matcher matchMultiplePatterns​(java.util.regex.Pattern[] patterns,
                                                                    java.lang.String input)
                                                             throws Parser.RegexException
        Matches multiple patterns against the input string and returns the first successful matcher
        Parameters:
        patterns - The array of regex patterns to match.
        input - The input string to match against.
        Returns:
        A Matcher for the first successful match.
        Throws:
        Parser.RegexException - If no patterns match the input or if patterns is empty.
      • isMatch

        public static boolean isMatch​(java.lang.String pattern,
                                      java.lang.String input)
      • isMatch

        public static boolean isMatch​(@Nonnull
                                      java.util.regex.Pattern pattern,
                                      java.lang.String input)
      • compatParseMap

        @Nonnull
        public static java.util.Map<java.lang.String,​java.lang.String> compatParseMap​(@Nonnull
                                                                                            java.lang.String input)