Posted By:
Saurabh_Johri
Posted On:
Monday, July 1, 2002 08:44 AM
Hi, I'm having the following problem with using regular expressions in util.regex: I have 2 Strings: String regex = "tree\s\w{1,4}.+\s=\s(.*;)"; String regrex1 = "\$1"; The problem that i'm having is that i am looking for the first regular expression (regex) in a String called editorEx, this part works fine, and the output says : " Parent RE recognised in Editor" .. However, the problems comes when i look for the second regular expression (regrex1) within the first regular expression (regrex) .. this should work because the first regular expression(regrex) has a capturing group, that i reference in regrex1, however this does not seem to work. The code
More>>
Hi,
I'm having the following problem with using regular expressions in util.regex:
I have 2 Strings:
String regex = "tree\s\w{1,4}.+\s=\s(.*;)";
String regrex1 = "\$1";
The problem that i'm having is that i am looking for the first regular expression (regex) in a String called editorEx, this part works fine, and the output says : " Parent RE recognised in Editor" ..
However, the problems comes when i look for the second regular expression (regrex1) within the first regular expression (regrex) .. this should work because the first regular expression(regrex) has a capturing group, that i reference in regrex1, however this does not seem to work.
The code i have so far is as follows, I hope that someone will be able to spot a glaring mistake!?!
Thanks very much for any assistance!
/*--------------------------------------------------------*/
pattern p = Pattern.compile(regrex);
Matcher m = p.matcher(editorEx);
boolean result = m.find();
if (result) {
JOptionPane.showMessageDialog(null, "Parent RE = recognised in editor);
String product = m.group(1);
}
else if(!result){
JOptionPane.showMessageDialog(null, "Parent RE = NOT recognised in editor);
}
m.reset(regrex1){
pattern newp = Pattern.compile(regrex1);
Matcher newm = newp.matcher(editorEx);
boolean result1 = newm.find();
if (result1){
JOptionPane.showMessageDialog(null, "1st Captured RE found within editor);
}
else if (!result1){
JOptionPane.showMessageDialog(null, "1st Captured RE NOT found within editor);
}
<<Less