Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Lourdes Edwards   on Apr 11 In Java Category.

  
Question Answered By: Lughaidh Fischer   on Apr 11


I got your regular  expression to work but I had to make some minor modifications
myself. The program  I wrote is included below as well as my output. I just
output the whole match. I'm also assuming that you're using Apache's Regexp
package. The text  string might come out all garbled by posting it this way
(looks like a hyperlink in Yahoo's mail window) but you get the idea.

import org.apache.regexp.*;
public class TestRegexp {
public static void main(String[] args) {
RE re = new RE("insrsid\\d*([^\\{\\}]*)\\\\cell \\}");
String text = "{\\b\\f2\\fs20\\insrsid4223016 TEXT 1\\cell }\\pard \\ql
\\li0\\ri0" +
"\\widctlpar\\intbl\\aspalpha\\aspnum\\faauto\\adjustright\\rin0\\lin0
{\\f2" +
"\\fs20\\insrsid4223016 \\trowd
\\irow0\\irowband0\\ts11\\trleft0\\trftsWidth1 " +
"\\clvertalt\\clbrdrt\\brdrnone \\clbrdrl\\brdrnone
\\clbrdrb\\brdrs\\brdrw15 " +
"\\clbrdrr\\brdrnone \\cltxlrtb\\clftsWidth3\\clwWidth18610\\clshdrawnil "
+
"\\cellx18610\\row }\\trowd \\irow1\\irowband1\\ts11\\trleft0\\trftsWidth1
" +
"\\clvertalt\\clbrdrt\\brdrs\\brdrw15 \\clbrdrl\\brdrnone
\\clbrdrb\\brdrnone " +
"\\clbrdrr\\brdrnone \\cltxlrtb\\clftsWidth3\\clwWidth9370\\clshdrawnil" +
"\\cellx9370\\clvertalt\\clbrdrt\\brdrs\\brdrw15 \\clbrdrl\\brdrnone " +
"\\clbrdrb\\brdrnone \\clbrdrr\\brdrnone
\\cltxlrtb\\clftsWidth3\\clwWidth9240" +
"\\clshdrawnil \\cellx18610\\pard \\ql \\li0\\ri0\\sb100" +
"\\widctlpar\\intbl\\faauto\\adjustright\\rin0\\lin0 {\\b\\f2\\fs20"+
"\\insrsid4223016 TEXT 2\\cell }";
boolean foundMatch = false;
int startPt = 0;
do {
foundMatch = re.match(text, startPt);
System.out.println(foundMatch);
if (foundMatch)
System.out.println(re.getParen(0));
startPt = re.getParenEnd(0);
}
while (foundMatch);
}
}


The output I get is:

true
insrsid4223016 TEXT 1\cell }
true
insrsid4223016 TEXT 2\cell }
false

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Regular expression help Or get search suggestion and latest updates.


Tagged: