Solved

java substring regex

Posted on 2010-11-18
3
710 Views
Last Modified: 2013-11-23
New York Housing May 11 F
New York Housing May12 Jun12 F
New York Housing May 12 Aug 12 O
NYMEX RBOB Gasoline Options Jan10 O

The last digit can be either F or O. The spaces can be present or not in between Month and Year and SecurityType (F or O)

Can you please give me the method to get the substring such that the method should return
201105 for the first one
201205201206 for the second one
201205201208 for the third one.
201001 for the fourth one.

in the fastest efficient way possible?

I need this in Java
0
Comment
Question by:srikanthrad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 34167547
Put those strings into an array called 'DATES' then try:

final Pattern DATE_PAT = Pattern.compile("([MJASONDF][a-z]{2})\\s*?(\\d{2})");
	for (String s : DATES) {
	    Matcher m = DATE_PAT.matcher(s);
	    while(m.find()) {
		System.out.println(m.group(1) + " " + m.group(2));
	    }
	    System.out.println();	
	}

Open in new window

0
 

Author Closing Comment

by:srikanthrad
ID: 34168614
Can you please explain the regular expression that is being used in the Pattern? Thanks.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 34172129
What bit don't you understand?
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
spring maven example issues 3 106
Code Coverage and Coding Standards 2 81
Java List 4 76
Session in java desktop 5 38
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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…
Suggested Courses

751 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