473,769 Members | 5,877 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="whitespac e" minLength="1"/>
<pattern type="number" minLength="1">
<capture label="Age"/>
</pattern>
<endAnchor/>
</regex>

Best regards,

Scott
Jul 20 '05 #1
6 3174
sc******@hotmai l.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******@hotma il.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="whitespac e" 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="definitio n">
<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><cha r value="A"/><char value="Z"/></cinterval>
<cinterval><cha r value="a"/><char value="z"/></cinterval>
</cclass>
<zero-or-more>
<cclass>
<cinterval><cha r value="A"/><char value="Z"/></cinterval>
<cinterval><cha r value="a"/><char value="z"/></cinterval>
<cinterval><cha r 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******@hotma il.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.c om
Jul 20 '05 #4

"Patrick TJ McPhee" <pt**@interlog. com> wrote in message
news:bp******** **@news.eusc.in ter.net...
In article <32************ **************@ posting.google. com>,
Scott Zuyderduyn <sc******@hotma il.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$6 C4.268056@pd7tw 1no>,
Scott Zuyderduyn <sc******@hotma il.com> wrote:

% "Patrick TJ McPhee" <pt**@interlog. com> wrote in message
% news:bp******** **@news.eusc.in ter.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.c om
Jul 20 '05 #6
On Sun, 16 Nov 2003 03:44:10 GMT, Scott Zuyderduyn <sc******@hotma il.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**********@kj davies.org reality in the hope that reality will
crack first is impressive, but futile"
-- Geoffrey Brent, rec.games.frp.d nd
Jul 20 '05 #7

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

Similar topics

6
2224
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": http://www.finseth.com/~fin/craft/ , I've come across the "buffer gap" representation for the text data of the buffer. Very briefly, it keeps the unallocated memory of the
1
4182
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 regular expressions easier to create and use (and in my experience as a regular expression user, it makes them MUCH easier to create and use.) I'm still working on formal documentation, and in any case, such documentation isn't necessarily the...
2
5100
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 have to use all the expressions seperately? Here are my regular expressions that check for valid email address and link Dim Expression As String =
4
5187
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 adate LIKE "2004.01.10 __:15") .... into something like this: .... where adate LIKE "2004.01.10 __:(30/15)" ...
7
3830
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 want to avoid that. My question here is if there is a way to pass either a memory stream or array of "find", "replace" expressions or any other way to avoid multiple copies of a string. Any help will be highly appreciated
3
3027
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 Expressions used in Perl identical to the Regular Expressions in PHP?
1
4386
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 the first regular expression that matches the string. I've gor the regular expressions ordered so that the highest priority is first (if two or more regular expressions match the string I want the first one returned) The code that does this has...
13
7492
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 be accomplished with regular expressions this way, such as validating a mathematical expression or parsing a language with nested parens, quoting or expressions. Another feature I'm missing is once-only subpatterns and possessive quantifiers...
12
2490
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 http://en.wikipedia.org/wiki/Regular_expression http://www.regular-expressions.info/javascript.html http://www.webreference.com/js/column5/
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10050
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9866
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7413
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.