Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Matching abitrary expression in a regular expression

Reply
Thread Tools

Matching abitrary expression in a regular expression

 
 
=?iso-8859-1?B?bW9vcJk=?=
Guest
Posts: n/a
 
      12-01-2005
Hi,
How to match a mathematical expression in a single regular expression?

 
Reply With Quote
 
 
 
 
Chris Uppal
Guest
Posts: n/a
 
      12-01-2005
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


 
Reply With Quote
 
 
 
 
Jeffrey Schwab
Guest
Posts: n/a
 
      12-01-2005
moop™ wrote:
> Hi,
> How to match a mathematical expression in a single regular expression?


..*
 
Reply With Quote
 
Chris Smith
Guest
Posts: n/a
 
      12-01-2005
Chris Uppal <> wrote:
> 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
 
Reply With Quote
 
Chris Uppal
Guest
Posts: n/a
 
      12-01-2005
Chris Smith wrote:

> 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


 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      12-01-2005
On 1 Dec 2005 01:17:09 -0800, "moop™" <> wrote, quoted
or indirectly quoted someone who said :

>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
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Oliver Wong
Guest
Posts: n/a
 
      12-01-2005

"Jeffrey Schwab" <> wrote in message
newsAEjf.100$. ..
> 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


 
Reply With Quote
 
Oliver Wong
Guest
Posts: n/a
 
      12-01-2005

"Chris Smith" <> wrote in message
news:.. .
>
> 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


 
Reply With Quote
 
Alan Moore
Guest
Posts: n/a
 
      12-02-2005
>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)."

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with regular expression for matching the url endings erenay Java 6 06-06-2006 08:16 PM
Regular Expression and string Matching/Replace sanjay010@yahoo.com Java 6 10-07-2005 03:36 AM
Regular Expression matching double quotes Codex Twin ASP .Net 1 04-18-2005 07:22 PM
Using XSLT to Filter out elements with CDATA matching a regular expression Edwin G. Castro XML 3 09-17-2004 05:12 PM
Dynamically changing the regular expression of Regular Expression validator VSK ASP .Net 2 08-24-2003 02:47 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57