Getting this error while running my own tests

java.util.regex.PatternSyntaxException: Dangling meta character '?' near index 0
?
^

my code part which causes the error

String afterslash = afterscheme.split("/", 2)[1];
String preourpath = afterslash.split("?", 2)[0];
String ourpath = "/" + preourpath;

and input is,

"scheme://unisaarland.de/12?blablabla"

I don’t know if these are enough to solve it but I will try my chance. Any ideas?

Thank you.

oguzhan

The question mark is a special character in regular expressions and stands for:
Zero or one occurrence of the last group.
It can be used for optional occurrences.

Therefore, you have to escape it using \\?.
The error tells you, that the problem is at position 0, at the start of the string.
In principle, it should even tell you the line.

Note: The question mark is also used in the lazy (also called minimal) arbitrary matching pattern .*? (or general patterns that are greedy by default).

A post was split to a new topic: Cannot invoke function because “userinfo” is null