RegExp on TextResource

51 views
Skip to first unread message

Alireza Rezaei Mahdiraji

unread,
May 30, 2015, 6:04:39 AM5/30/15
to google-we...@googlegroups.com

Hi All,

I am trying to apply a regular expression on a TextResource (which is an html file),

but it does not work. I can see the content of the resource as strign. If I provide the content of the file directly to RegExp it works.

String html = ReadHtmlResources.INSTANCE.
                    getDocumentationHtml().getText();

RegExp regExp = RegExp.compile("<p id='pid'>(.*?)</p>");

MatchResult matcher = regExp.exec(html);

boolean matchFound = matcher != null; // returns false


Any idea why this does not work?

Cheers,
Alireza

Ignacio Baca Moreno-Torres

unread,
Jun 4, 2015, 2:31:58 AM6/4/15
to google-we...@googlegroups.com
Not sure whats your problem, maybe 'multiline text' is causing the regex to fail.

Alternatively, you can use GQuery and work with the nodes instead of strings. Something like (html must start with '<')...
Gquery root = $(html);
// to read...
String pInnerHtml = root.filter(true,"#pid").html();
// to write...
root
.filter(true,"#pid").html("updated <b>content</b>");
// finally, append to the dom
root
.appendTo(somePlace);
Reply all
Reply to author
Forward
0 new messages