Solved

Change String by pattern

Posted on 2009-05-04
2
174 Views
Last Modified: 2012-05-06
Hi.
Have a preatty easy question. I need the simplest way to do this:

I have Strings like: 12399, 12500, 12204, 1208, 07
I need them to be like this: "123/ 99", "123/ 00", 122/ 04", "12/ 08", "/ 07"

Please note that the last two is valid.
The pattern is "xxxx/ yy" where yy is mandatory.

Any ideas?
0
Comment
Question by:kristian_gr
  • 2
2 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 24296390
Try
s = s.replaceAll("(\\d*)(\\d{2})", "$1/$2");

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24296721
:-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
spring jars download 1 52
Convert from a json string array to a Java object 3 64
JAVA API design with micro service cloud in mind 1 77
Java pass by reference 3 18
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question