matcher

java regex pattern unclosed character class

浪尽此生 提交于 2019-11-26 23:17:27
I need some help. Im getting: Caused by: java.util.regex.PatternSyntaxException: Unclosed character class near index 24 ^[a-zA-Z└- 0-9£µ /.'-\]*$ ^ at java.util.regex.Pattern.error(Pattern.java:1713) at java.util.regex.Pattern.clazz(Pattern.java:2254) at java.util.regex.Pattern.sequence(Pattern.java:1818) at java.util.regex.Pattern.expr(Pattern.java:1752) at java.util.regex.Pattern.compile(Pattern.java:1460) at java.util.regex.Pattern.<init>(Pattern.java:1133) at java.util.regex.Pattern.compile(Pattern.java:823) Here is my code: String testString = value.toString(); Pattern pattern = Pattern

How to extract parameters from a given url

房东的猫 提交于 2019-11-26 22:24:34
In Java I have: String params = "depCity=PAR&roomType=D&depCity=NYC"; I want to get values of depCity parameters (PAR,NYC). So I created regex: String regex = "depCity=([^&]+)"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(params); m.find() is returning false. m.groups() is returning IllegalArgumentException . What am I doing wrong? It doesn't have to be regex. Since I think there's no standard method to handle this thing, I'm using something that I copied from somewhere (and perhaps modified a bit): public static Map<String, List<String>> getQueryParams(String url) { try { Map

java regex pattern unclosed character class

半城伤御伤魂 提交于 2019-11-26 17:27:13
问题 I need some help. Im getting: Caused by: java.util.regex.PatternSyntaxException: Unclosed character class near index 24 ^[a-zA-Z└- 0-9£µ /.'-\]*$ ^ at java.util.regex.Pattern.error(Pattern.java:1713) at java.util.regex.Pattern.clazz(Pattern.java:2254) at java.util.regex.Pattern.sequence(Pattern.java:1818) at java.util.regex.Pattern.expr(Pattern.java:1752) at java.util.regex.Pattern.compile(Pattern.java:1460) at java.util.regex.Pattern.<init>(Pattern.java:1133) at java.util.regex.Pattern

Java Pattern Matcher: create new or reset?

耗尽温柔 提交于 2019-11-26 16:58:32
问题 Assume a Regular Expression , which, via a Java Matcher object, is matched against a large number of strings: String expression = ...; // The Regular Expression Pattern pattern = Pattern.compile(expression); String[] ALL_INPUT = ...; // The large number of strings to be matched Matcher matcher; // Declare but not initialize a Matcher for (String input:ALL_INPUT) { matcher = pattern.matcher(input); // Create a new Matcher if (matcher.matches()) // Or whatever other matcher check { // Whatever

Replace HTML codes with equivalent characters in Java [duplicate]

旧街凉风 提交于 2019-11-26 14:31:34
问题 This question already has an answer here: How to unescape HTML character entities in Java? 10 answers Currently I'm working on converting HTML codes with equivalent characters in java. I need to convert the below code to characters. è - è ® - ® & - & ñ - ñ & - & I tried using the regex pattern (&#x)([\\d|\\w]*)([\\d|\\w]*)([\\d|\\w]*)([\\d|\\w]*)(;) When I debug, matcher.find() gives me true but the control skips the loop where I have written the code for conversion. Don't know what is

Java regex to match start/end tags causes stack overflow

随声附和 提交于 2019-11-26 11:39:27
问题 The standard implementation of the Java Pattern class uses recursion to implement many forms of regular expressions (e.g., certain operators, alternation). This approach causes stack overflow issues with input strings that exceed a (relatively small) length, which may not even be more than 1,000 characters, depending on the regex involved. A typical example of this is the following regex using alternation to extract a possibly multiline element (named Data ) from a surrounding XML string,

PatternSyntaxException: Illegal Repetition when using regex in Java

若如初见. 提交于 2019-11-26 09:46:43
问题 I don\'t know much regex, but I need to match a simple pattern. The following should return true, Pattern.matches(\"{\\\"user_id\\\" : [0-9]*}\", inputLine) when inputLine is {\"user_id\" : 34} However, I\'m getting this exception: java.util.regex.PatternSyntaxException: Illegal repetition {\"user_id\" : 24} at java.util.regex.Pattern.error(Unknown Source) at java.util.regex.Pattern.closure(Unknown Source) at java.util.regex.Pattern.sequence(Unknown Source) at java.util.regex.Pattern.expr

How to extract parameters from a given url

点点圈 提交于 2019-11-26 08:16:27
问题 In Java I have: String params = \"depCity=PAR&roomType=D&depCity=NYC\"; I want to get values of depCity parameters (PAR,NYC). So I created regex: String regex = \"depCity=([^&]+)\"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(params); m.find() is returning false. m.groups() is returning IllegalArgumentException . What am I doing wrong? 回答1: It doesn't have to be regex. Since I think there's no standard method to handle this thing, I'm using something that I copied from somewhere

java regex match count

女生的网名这么多〃 提交于 2019-11-26 04:37:28
Let's say I have a file, and the file contains this: HelloxxxHelloxxxHello I compile a pattern to look for 'Hello' Pattern pattern = Pattern.compile("Hello"); Then I use an inputstream to read in the file and convert it into a String so that it can be regexed. Once the matcher finds a match in the file, it indicates this, but it doesn't tell me how many matches it found; simply that it found a match within the String. So, as the string is relatively short, and the buffer I'm using is 200 bytes, it should find three matches. However, it just simply says match, and doesn't provide me with a