Results 1 to 4 of 4
- 03-18-2012, 04:29 AM #1
Regex Q - gotta be something obvious
SSCCE:
The output is 3 elements, "", "1", and "32". I expected 2 elements, "1" and "32". What gives?Java Code:public class SplitEscape { public static void main(String[] args) { String string = (char) 27 + "[1;32m"; String[] split = string.split("[^0-9]+"); System.out.printf("The resulting array has %d elements.\n", split.length); } }Get in the habit of using standard Java naming conventions!
-
Re: Regex Q - gotta be something obvious
What is the motivation driving this? What is your ultimate goal with this code?
- 03-18-2012, 04:42 AM #3
Re: Regex Q - gotta be something obvious
NM - found the answer on StackOverflow. This is just how it is when there's a leading delimiter.
An inefficient but simple solution:
Java Code:input.replaceFirst("^"+regex, "").split(regex);Get in the habit of using standard Java naming conventions!
- 03-18-2012, 06:52 AM #4
Similar Threads
-
Regex help?
By l3ane in forum New To JavaReplies: 6Last Post: 01-18-2011, 06:04 AM -
This will have an obvious answer!
By MarkusHendersonicus in forum New To JavaReplies: 6Last Post: 12-24-2010, 12:49 AM -
Using Regex
By ron87 in forum New To JavaReplies: 4Last Post: 09-12-2010, 06:26 AM -
Please Help - Regex
By BeeGee in forum Advanced JavaReplies: 0Last Post: 04-28-2010, 05:28 PM -
gotta loving this forum
By Y. Progammer in forum Suggestions & FeedbackReplies: 0Last Post: 02-20-2010, 10:28 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks