Solved

Change String by pattern

Posted on 2009-05-04
2
171 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groovy example issue 10 88
Cipher Configuration on Apache HTTPD 4 50
Basic Java Case or If-Else statement... 3 43
reverse digits of a number using for loop 5 36
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

932 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now