regex - Java exception for using String.Split() method: Dangling meta character -
i'm trying parse url string (which receiving via html method) , extract embedded options. i'm wondering why drops exception on s=s.split("?")[0];
exception in thread "main" java.util.regex.patternsyntaxexception: dangling meta character '?' near index 0
public static void main(string[] args) { string s= "run.html?yse=yse1&tracefile=capacity.1mbps_c50.txt&fd=100&rd=100&down=1&up=1&per=0.00001"; s=s.split("?")[0]; //drops error string ss[]=s.split("&"); //this class have receives array of splitted options. javarunemulator j = new javarunemulator(ss); system.out.println(j.getoutput()); }
from documentation split() method takes regular expression input.
public string[] split(string regex) splits string around matches of given regular expression.
the character ? used identify patterns in regex, including of following
greedy quantifiers x? : x, 1 time or not @ all
reluctant quantifiers x?? : x, 1 time or not @ all x*? : x, 0 or more times x+? : x, 1 or more times x{n}? : x, n times x{n,}? : x, @ to the lowest degree n times x{n,m}? : x, @ to the lowest degree n not more m times
possessive quantifiers x?+ : x, 1 time or not @ all
if escape string this
s=s.split("\\?")[0]; the ? won't treated beingness used in pattern , instead raw string.
java regex
No comments:
Post a Comment