Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

Matching abitrary expression in a regular expression

Thread view: 
moop™ - 01 Dec 2005 09:17 GMT
Hi,
How to match a mathematical expression in a single regular expression?
Chris Uppal - 01 Dec 2005 12:13 GMT
moopT wrote:

> How to match a mathematical expression in a single regular expression?

You can't.  Mathematical expressions make use of nested brackets.  Regexps
don't have the power to handle arbitrarily nested constructs.

   -- chris
Chris Smith - 01 Dec 2005 17:52 GMT
> You can't.  Mathematical expressions make use of nested brackets.  Regexps
> don't have the power to handle arbitrarily nested constructs.

Interestingly, I was informed some time ago that modern Perl regular
expressions CAN do so... suggesting that perhaps in the name of
correctness, Perl programmers ought to stop calling them "regular
expressions" and start calling them "context-free expressions".  Java,
though, does not include the Perl madness that makes this possible.  To
quote from the API docs:

   Perl constructs not supported by this class:
       [...]
       The embedded code constructs (?{code}) and (??{code}),

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Chris Uppal - 01 Dec 2005 18:24 GMT
> Interestingly,

Yes, it /is/ interesting.  I could find other adjectives, though.

>                 I was informed some time ago that modern Perl regular
> expressions CAN do so... suggesting that perhaps in the name of
> correctness, Perl programmers ought to stop calling them "regular
> expressions" and start calling them "context-free expressions".

I suggest the name "aggregations of ill-considered hacks".

>         The embedded code constructs (?{code}) and (??{code}),

Ugggh!

Is it possible to write a device driver in Perl regexps yet ?

   -- chris
Oliver Wong - 01 Dec 2005 22:09 GMT
> Interestingly, I was informed some time ago that modern Perl regular
> expressions CAN do so... suggesting that perhaps in the name of
> correctness, Perl programmers ought to stop calling them "regular
> expressions" and start calling them "context-free expressions".

   From what I understand, Perl's implementation of "regular expression"
allows for arbitrary back-references. If this is true, then the expressive
power of these expressions is greater than context-free languages as well,
so "context-free expressions" would also be a misnomer.

   Maybe something like "Turing expressions", though so many things are
named after Alan Turing already that I wouldn't be surprised if "Turing
expressions" already has some other meaning.

   - Oliver
Alan Moore - 02 Dec 2005 00:51 GMT
>From the Wikipedia link above:

"'[R]egular expressions' [...] are only marginally related to real
regular expressions. Nevertheless, the term has grown with the
capabilities of our pattern matching engines, so I'm not going to try
to fight linguistic necessity here. I will, however, generally call
them "regexes" (or "regexen", when I'm in an Anglo-Saxon mood)."
Jeffrey Schwab - 01 Dec 2005 15:24 GMT
moop™ wrote:
> Hi,
> How to match a mathematical expression in a single regular expression?

.*
Oliver Wong - 01 Dec 2005 22:06 GMT
> moop™ wrote:
>> Hi,
>> How to match a mathematical expression in a single regular expression?
>
> .*

   I believe that in formal language theory, they define "match" as
accepting all the strings from a certain set of strings, and not accepting
that set's complement with respect to a fixed alphabet.

   (Since this is posted on a Java newsgroup, we can assume that the
alphabet is Unicode, and the implementation of regexp used is Sun's
implementation).

   So actually ".*" does not "match" the set of "mathematical expressions"
because "Hello World!" is not a mathematical expression, and yet it is
accepted by the provided regular expression.

See: http://en.wikipedia.org/wiki/Regular_expression

   - Oliver
Roedy Green - 01 Dec 2005 19:15 GMT
>How to match a mathematical expression in a single regular expression?

You could do it if you limited yourself to a few patterns, but regexes
don't understand matching nested delimiters.  You need a simple parser
instead. It is not nearly as difficult as you might think. There are
many canned parsers already done for common tasks.  See
http://mindprod.com/jgloss/parser.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.