Matching abitrary expression in a regular expression

  • Thread starter =?iso-8859-1?B?bW9vcJk=?=
  • Start date
?

=?iso-8859-1?B?bW9vcJk=?=

Hi,
How to match a mathematical expression in a single regular expression?
 
C

Chris Uppal

moopT said:
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
 
C

Chris Smith

Chris Uppal said:
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}),

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

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
C

Chris Uppal

Chris said:
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
 
R

Roedy Green

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
 
O

Oliver Wong

Jeffrey Schwab said:

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
 
O

Oliver Wong

Chris Smith said:
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
 
A

Alan Moore

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top