473,398 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

XML representation of regular expressions

Hi all,

I've started planning a software project that utilizes XML to store a lot of
different input from the user. Regular expressions comprise a portion of
this input. I could store a regex as a plain string ("^(\w+)\s+(\d+)$"),
but this assumes POSIX-style regular expressions, and the software
requirements can't neccessarily assume this. Has anyone ever created or
seen an XML spec of a regular expression? For example, something that would
result in:

<regex>
<startAnchor/>
<pattern type="word" minLength="1">
<capture label="Name"/>
</pattern>
<pattern type="whitespace" minLength="1"/>
<pattern type="number" minLength="1">
<capture label="Age"/>
</pattern>
<endAnchor/>
</regex>

Best regards,

Scott
Jul 20 '05 #1
6 3152
sc******@hotmail.com (Scott Zuyderduyn) writes:
I could store a regex as a plain string ("^(\w+)\s+(\d+)$"),
but this assumes POSIX-style regular expressions, and the software
requirements can't neccessarily assume this.


This only assumes, that the regex is a string.
Non-POSIX-style regular expressions are strings as well,
or are there any non-string regular expressions?
If there are different regular-expression-languages
used, the languages needs to be stored with the regex:

<regex lang="POSIX" code="^(\w+)\s+(\d+)$" />

Parsing different kinds of regular expression languages
into an XML-tree might become a large effort, that should
be made only for good reasons.

Jul 20 '05 #2
Scott Zuyderduyn <sc******@hotmail.com> wrote:
I've started planning a software project that utilizes XML to store a lot of
different input from the user. Regular expressions comprise a portion of
this input. I could store a regex as a plain string ("^(\w+)\s+(\d+)$"),
but this assumes POSIX-style regular expressions, and the software
requirements can't neccessarily assume this. Has anyone ever created or
seen an XML spec of a regular expression? For example, something that would
result in:

<regex>
<startAnchor/>
<pattern type="word" minLength="1">
<capture label="Name"/>
</pattern>
<pattern type="whitespace" minLength="1"/>
<pattern type="number" minLength="1">
<capture label="Age"/>
</pattern>
<endAnchor/>
</regex>


I try currently some efforts in this direction, but more to
build a parser with uses regex like XML structures.

My approach uses a combination of a ELR(0) and a Tomita style parser.

Something like

<definition name="definition">
<sequence>
<element name="name"/>
<element name="ws"/>
<char value=":"/>
<element name="ws"/>
<element name="regex"/>
<element name="ws"/>
<char value=";"/>
</sequence>
</definition>

<definition name="name">
<sequence>
<cclass>
<cinterval><char value="A"/><char value="Z"/></cinterval>
<cinterval><char value="a"/><char value="z"/></cinterval>
</cclass>
<zero-or-more>
<cclass>
<cinterval><char value="A"/><char value="Z"/></cinterval>
<cinterval><char value="a"/><char value="z"/></cinterval>
<cinterval><char value="0"/><char value="9"/></cinterval>
<char value="_"/>
<char value="-"/>
</cclass>
</zero-or-more>
</sequence>
</definition>

If you're interested in than see http://chaperon.sourceforge.net/

Stephan Michels.

Jul 20 '05 #3
In article <32**************************@posting.google.com >,
Scott Zuyderduyn <sc******@hotmail.com> wrote:

% different input from the user. Regular expressions comprise a portion of
% this input. I could store a regex as a plain string ("^(\w+)\s+(\d+)$"),
% but this assumes POSIX-style regular expressions, and the software

Apropos of nothing at all, that's not a POSIX-style regular expression.

% requirements can't neccessarily assume this. Has anyone ever created or
% seen an XML spec of a regular expression?

Even the XML schemas spec resisted the temptation to do this, in favour
of a compact format.
--

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #4

"Patrick TJ McPhee" <pt**@interlog.com> wrote in message
news:bp**********@news.eusc.inter.net...
In article <32**************************@posting.google.com >,
Scott Zuyderduyn <sc******@hotmail.com> wrote:

% different input from the user. Regular expressions comprise a portion of % this input. I could store a regex as a plain string ("^(\w+)\s+(\d+)$"), % but this assumes POSIX-style regular expressions, and the software

Apropos of nothing at all, that's not a POSIX-style regular expression.
Indeed - too much Perl for me.

% requirements can't neccessarily assume this. Has anyone ever created or
% seen an XML spec of a regular expression?

Even the XML schemas spec resisted the temptation to do this, in favour
of a compact format.
--


Yes, a compact form is pragmatic, but idealistically it's a departure I
would think. Shouldn't anything more than a simple data type really be
described in XML? And regular expressions can be so arcane, an XML based
representation might actually be more easily understood if it was done
properly. I can understand in the context of having reasonably compact XML
Schemas, but it's still a surprise to me that I couldn't find a "mainstream"
regex spec.

Regards,

Scott
Jul 20 '05 #5
In article <eoCtb.401422$6C4.268056@pd7tw1no>,
Scott Zuyderduyn <sc******@hotmail.com> wrote:

% "Patrick TJ McPhee" <pt**@interlog.com> wrote in message
% news:bp**********@news.eusc.inter.net...

% > Even the XML schemas spec resisted the temptation to do this, in favour
% > of a compact format.

% described in XML? And regular expressions can be so arcane, an XML based
% representation might actually be more easily understood if it was done
% properly. I can understand in the context of having reasonably compact XML
% Schemas, but it's still a surprise to me that I couldn't find a "mainstream"
% regex spec.

I'm not disagreeing with you. My feeling is that the schema working group
had no interest in creating a reasonably compact xml representation for
schemas, so my guess is that if they didn't take it on, nobody has. It may
be just a matter of time. It seems like there are a lot of people
expressing context-free grammars in XML.
--

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #6
On Sun, 16 Nov 2003 03:44:10 GMT, Scott Zuyderduyn <sc******@hotmail.com> wrote:

Yes, a compact form is pragmatic, but idealistically it's a departure I
would think. Shouldn't anything more than a simple data type really be
described in XML?
Not necessarily. I've read in books about SGML that the creators freely
acknowledge that SGML is not the best way to store all types of data.
Being able to drop to a more specific, non-SGML syntax is useful. The
same is probably true of XML.

For instance, in some software I'm working on for an RPG, we need to be
able to represent random die rolls. It is possible to break it down to
something like

<roll>
<diecount>2</diecount>
<diesize>8</diesize>
<modifier>-2</modifier>
</roll>

but it makes much more sense to do

<roll expression='2d8-2' />

(or more likely, it'd be an attribute of whatever the roll applies to --
<damage roll='2d8-2' />)

I'm not a purist when it comes to XML; I think the amount of effort
needed to understand and use something should be proportional to the
importance of the individual components.
And regular expressions can be so arcane, an XML based
representation might actually be more easily understood if it was done
properly.


That's the rub. It wouldn't be easy. IMO, an RE is most easily
understood if you can *see* the thing. Counting parentheses isn't a big
deal. A complex RE (say, one that runs to one or two hundred
characters) would be a *nightmare* to try to read and understand if done
in XML -- at least, if each term had to be encoded in its own element.

That said, I can see ways to make things a little easier. You might use
allow an RE component to contain the 'arcane' parts but use XML elements
to link them together. For instance, an RE such as:

([A-Za-z]+|[0-9]+)

might be represented something like

<re var='var1'>
<choose>
<re>[A-Za-z]+</re>
<re>[0-9]+</re>
</choose>
</re>

This isn't *too* hideous. It is not nearly as concise as the first, and
mixes technologies. The latter is the bigger problem IMO.

Trying to fully-describe RE in XML would be horribly painful. Go ahead
and fall back on other representations for data where it makes sense;
this is one case.
Keith
--
Keith Davies "Your ability to bang your head against
ke**********@kjdavies.org reality in the hope that reality will
crack first is impressive, but futile"
-- Geoffrey Brent, rec.games.frp.dnd
Jul 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: manders2k | last post by:
Hi all -- I'm contemplating the idea of writing a simple emacs-like editor in python (for fun and the experience of doing so). In reading through Craig Finseth's "The Craft of Text Editing": ...
1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
2
by: Sehboo | last post by:
Hi, I have several regular expressions that I need to run against documents. Is it possible to combine several expressions in one expression in Regex object. So that it is faster, or will I...
4
by: Együd Csaba | last post by:
Hi All, I'd like to "compress" the following two filter expressions into one - assuming that it makes sense regarding query execution performance. .... where (adate LIKE "2004.01.10 __:30" or...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
3
by: a | last post by:
I'm a newbie needing to use some Regular Expressions in PHP. Can I safely use the results of my tests using 'The Regex Coach' (http://www.weitz.de/regex-coach/index.html) Are the Regular...
1
by: Allan Ebdrup | last post by:
I have a dynamic list of regular expressions, the expressions don't change very often but they can change. And I have a single string that I want to match the regular expressions against and find...
13
by: Wiseman | last post by:
I'm kind of disappointed with the re regular expressions module. In particular, the lack of support for recursion ( (?R) or (?n) ) is a major drawback to me. There are so many great things that can...
12
by: FAQEditor | last post by:
Anybody have any URL's to tutorials and/or references for Regular Expressions? The four I have so far are: http://docs.sun.com/source/816-6408-10/regexp.htm...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.