Solved

Change String by pattern

Posted on 2009-05-04
2
173 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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
Protect jar file - windows app 2 65
jsp login check 12 42
Glassfish admin console not working 1 33
running on tomcat not jboss eap 7.0 3 18
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

837 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