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]
# 1
Can't be done. Use a proper parser.
YAT_Archivista at 2007-7-9 6:11:06 > top of Java-index,Java Essentials,Java Programming...
# 2
Please explain....and how do I go about it..?Thanks.
Etoa at 2007-7-9 6:11:06 > top of Java-index,Java Essentials,Java Programming...
# 3
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.
kevjavaa at 2007-7-9 6:11:06 > top of Java-index,Java Essentials,Java Programming...
# 4
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 > top of Java-index,Java Essentials,Java Programming...
# 5
> Can't be done. Use a proper parser.Just to give Sabre a giggle: pumping lemma!kind regards,Jos ;-)
JosAHa at 2007-7-9 6:11:06 > top of Java-index,Java Essentials,Java Programming...
# 6
> > Can't be done. Use a proper parser.> > Just to give Sabre a giggle: pumping lemma!> > kind regards,> > Jos ;-)He He He He He ... :-)
sabre150a at 2007-7-9 6:11:06 > top of Java-index,Java Essentials,Java Programming...
# 7

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.

kevjavaa at 2007-7-9 6:11:06 > top of Java-index,Java Essentials,Java Programming...
# 8

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

Joerg22a at 2007-7-9 6:11:06 > top of Java-index,Java Essentials,Java Programming...
# 9

> > 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.

kevjavaa at 2007-7-9 6:11:06 > top of Java-index,Java Essentials,Java Programming...
# 10
> > > 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
JosAHa at 2007-7-9 6:11:06 > top of Java-index,Java Essentials,Java Programming...
# 11

> > > 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

JosAHa at 2007-7-9 6:11:06 > top of Java-index,Java Essentials,Java Programming...
# 12
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 :).
kevjavaa at 2007-7-9 6:11:06 > top of Java-index,Java Essentials,Java Programming...