Sunday, April 28, 2013

Java Exercise #103: Simple RegEx

Exercise: Write a program that splits a string based on empty space and replace empty space with tab.

EXAMPLE_TEST is This is my small example string which I'm going to use for pattern matching.

EXAMPLE_TEST.matches("\w.*"): true

Splitting with space: EXAMPLE_TEST.split("\s+")
This
is
my
small
example
string
which
I'm
going
to
use
for
pattern
matching.

Replace all white space with tab: EXAMPLE_TEST.replaceAll("\s+", "\t")
This is my small example string which I'm going to use for pattern matching.

Download Code: Simple RegEx

No comments:

Post a Comment