How to use String.startWith(..) to ignore leading whitespace?
Let's say I have the following that start with "needle", ignoring leading
whitespace:
String haystack = "needle#####^&%#$^%...";
String haystackWithSpace = " needle******!@@#!@@%@%!$...";
I want to capture anything that starts with "needle" or "/s*needle"(if
there was a regex allowed). Is there an elegant way to do this without
calling .trim()? Or is there a way to make a regex work here? I want the
following to be true:
haystackWithSpace.startsWith("needle"); // doesn't ignore leading whitespace
haystackWithSpace.startsWith("/s*needle"); // doesn't work
Basically, is there a String s that will satisfy the following?:
haystack.startsWith(s) == haystackWithSpace.startsWith(s);
No comments:
Post a Comment