How to match a regular expression in Java?

Posted on 2013-09-25
Medium Priority
Last Modified: 2013-09-25
How can I match the following regular expression in JAVA?

If commandLineOutput has something like "########_####_##_check_Standards_ALL_Files.xml"

Then I Iwould like to catch this match.

commandLineOutput is this: 20130925_1603_28_check_Standards_ALL_Files.xml

Then we will catch this match

Open in new window

if (commandLineOutput has this match)

then assign this match to a variable

Open in new window

Question by:Tolgar
1 Comment
LVL 35

Accepted Solution

Terry Woods earned 2000 total points
ID: 39522855
Something like this?

 if (commandLineOutput.matches("^\\d{8}_\\d{4}_\\d\\d_check_Standards_ALL_Files\\.xml") == true)

Open in new window

I've assumed the value you're searching for will be at the start of the string. If that's not the case, remove the ^ character from the pattern.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

621 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