• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

regex find value of radio button

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
brimful
Asked:
brimful
  • 3
  • 2
1 Solution
 
CEHJCommented:
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
 
brimfulAuthor Commented:
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
 
CEHJCommented:
final String RE = ".+=\"(.*?2005[^\"]+)";
0
 
CEHJCommented:
:-)
0
 
brimfulAuthor Commented:
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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now