Regular Expression
Hi guys,
How do u write a regular expression that matches JavaScript codes in a html page.
So, far I can only match something like this:
-
function functionName () {
but I want to match everything that is between the " { } ".
Any help on doing that will be appreciated...
Thanks,
[328 byte] By [
Etoa] at [2007-11-26 18:37:02]

Can't be done. Use a proper parser.
Please explain....and how do I go about it..?Thanks.
Etoa at 2007-7-9 6:11:06 >

Actually, it can be done, but it would be a kludge. http://java.sun.com/docs/books/tutorial/essential/regex/ (if you insist)Really -- use a proper parser.
Thanks for the link, I've been using the same page to learn regExpression... how do I go about using the so called "proper parser"Thanks..
Etoa at 2007-7-9 6:11:06 >

> Can't be done. Use a proper parser.Just to give Sabre a giggle: pumping lemma!kind regards,Jos ;-)
> > Can't be done. Use a proper parser.> > Just to give Sabre a giggle: pumping lemma!> > kind regards,> > Jos ;-)He He He He He ... :-)
Try JSel:
[url=http://sourceforge.net/projects/jsel]Sourceforge page[/url]
[url=http://wiki.hammurapi.biz/index.php?title=How_to_parse_Java_file_with_Jsel]Example[/url]
Seems to be geared at parsing Java files using Java.
Edit: Ignore me. I'm a dunce.May I be lashed repeatedly with a wet noodle. OP asked for JavaScript, I handed him a Java parser.
Well, just to match your above string you could do a
String s= "function fname() {1234,laksjd asdfasdaklj \njk d56}";
Pattern pat= Pattern.compile("function .+()\\{.+\\}", Pattern.DOTALL);
Provided there are no further braces within the braces.
But will this be sufficient?
Message was edited by:
Joerg22
> > Can't be done. Use a proper parser.
>
> pumping lemma!
I stand corrected. A regex can't reliably do the job.
http://en.wikipedia.org/wiki/Pumping_lemma
For the curious. The page makes my brain hurt every time I try to read it. Sorry, YAT_Archivist.
> > > Can't be done. Use a proper parser.> > > > Just to give Sabre a giggle: pumping lemma!> > He He He He He ... :-)I knew you'd appreciate it ;-)kind regards,Jos
> > > Can't be done. Use a proper parser.
> >
> > pumping lemma!
>
> I stand corrected. A regex can't reliably do the job.
>
> http://en.wikipedia.org/wiki/Pumping_lemma
>
> For the curious. The page makes my brain hurt every
> time I try to read it. Sorry, YAT_Archivist.
It isn't that hard; if you click on the "Pumping Lemma for Regular Languages"
link (don't laugh Sabre) and substitute '(' for 'a' and ')' for 'b' you'd see
that not even a simple string of properly nested parentheses can be
a regular language, so e.g. '(()(()))' is far out.
kind regards,
Jos ;-)
Message was edited by:
JosAH
Here's a cute little rhyme for you guys: http://www.cs.brandeis.edu/~mairson/poems/node1.htmlThanks for the explanation, Jos... makes sense, but the Wikipedia page still makes my head hurt :).