Matching abitrary expression in a regular expression

Discussion in 'Java' started by =?iso-8859-1?B?bW9vcJk=?=, Dec 1, 2005.

  1. Hi,
    How to match a mathematical expression in a single regular expression?
    =?iso-8859-1?B?bW9vcJk=?=, Dec 1, 2005
    #1
    1. Advertising

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

    Chris Uppal Guest

    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 Uppal, Dec 1, 2005
    #2
    1. Advertising

  3. moop™ wrote:
    > Hi,
    > How to match a mathematical expression in a single regular expression?


    ..*
    Jeffrey Schwab, Dec 1, 2005
    #3
  4. =?iso-8859-1?B?bW9vcJk=?=

    Chris Smith Guest

    Chris Uppal <-THIS.org> 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
    Chris Smith, Dec 1, 2005
    #4
  5. =?iso-8859-1?B?bW9vcJk=?=

    Chris Uppal Guest

    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
    Chris Uppal, Dec 1, 2005
    #5
  6. =?iso-8859-1?B?bW9vcJk=?=

    Roedy Green Guest

    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.
    Roedy Green, Dec 1, 2005
    #6
  7. =?iso-8859-1?B?bW9vcJk=?=

    Oliver Wong Guest

    "Jeffrey Schwab" <> wrote in message
    news:eek:AEjf.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
    Oliver Wong, Dec 1, 2005
    #7
  8. =?iso-8859-1?B?bW9vcJk=?=

    Oliver Wong Guest

    "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
    Oliver Wong, Dec 1, 2005
    #8
  9. =?iso-8859-1?B?bW9vcJk=?=

    Alan Moore Guest

    >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)."
    Alan Moore, Dec 2, 2005
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    2
    Views:
    2,266
  2. Codex Twin
    Replies:
    1
    Views:
    669
    Wessel Troost
    Apr 18, 2005
  3. Replies:
    6
    Views:
    844
    John C. Bollinger
    Oct 7, 2005
  4. Edwin G. Castro
    Replies:
    3
    Views:
    3,638
    Edwin G. Castro
    Sep 17, 2004
  5. erenay
    Replies:
    6
    Views:
    4,898
    Jussi Piitulainen
    Jun 6, 2006
Loading...

Share This Page