?
Solved

regex find value of radio button

Posted on 2005-03-13
5
Medium Priority
?
270 Views
Last Modified: 2012-05-05
Hi there

I've got an html file part of which looks like:

<input type="radio" name="fkDepartID" value="2176|10567|10540~139~2005-05-30 12:40:00">
<input type="radio" name="fkDepartID" value="848|5893|5919~99~2005-06-03 09:05:00">
<input type="radio" name="fkDepartID" value="2177|10568|10541~139~2005-06-06 12:40:00">
<input type="radio" name="fkDepartID" value="5736~99~2005-06-07 11:15:00">

Say if I want the value of the "value" attribute  where part of the attribute looks like: 2005-05-30

how would I use this to return "2176|10567|10540~139~2005-05-30 12:40:00"?

Similarly it has to work with all attribute values.
0
Comment
Question by:brimful
[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
  • 3
  • 2
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 13528292
Try something like:

// (import java.util.regex.*)
String input = "<input type=\"radio\" name=\"fkDepartID\" value=\"2176|10567|10540~139~2005-05-30 12:40:00\">";
final String RE = ".+=.*?(2005[^\"]+)";
Pattern pat = Pattern.compile(RE);
Matcher mat = pat.matcher(input);
while(mat.find()) {
      System.out.println(mat.group(1));
}
0
 

Author Comment

by:brimful
ID: 13528306
if I search for "2005-05-30" the it shoudl return 2176|10567|10540~139~2005-05-30 12:40:00

similarly if I want to search for 2005-06-03 then it should return "848|5893|5919~99~2005-06-03 09:05:00"
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 13528316
final String RE = ".+=\"(.*?2005[^\"]+)";
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13528379
:-)
0
 

Author Comment

by:brimful
ID: 13528424
one more thing

say if I have this html

<input type="radio" name="fkDepartID" value="2176|10567|10540~139~2005-05-30 12:40:00">


<input type="radio" name="fkReturnID" value="0567|10540~139~2005-05-30 12:40:00">


how can I grab the value only from that tag where name="fkDepartID"?

eg: if I want to search for date 2005-05-30 I want return only

2176|10567|10540~139~2005-05-30 12:40:00 and not 0567|10540~139~2005-05-30 12:40:00

even though both dates are matched.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month9 days, 16 hours left to enroll

762 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