Re: Regular Expression Question

37 views
Skip to first unread message

Mark Tarver

unread,
Oct 9, 2012, 8:19:01 AM10/9/12
to Qilang
Eric actually did work on this and I wanted to incorporate it into the
standard library. I'll have a look at what he did.

Mark

On Oct 9, 12:46 am, Jacob <submissionfight...@gmx.com> wrote:
> After all the talk of regular expression earlier, I figured I would ask
> this question here.  I would like to know how to use a regular expression
> to find the closing paranthesis of an sexp.  Such as...  [(blah (blah q w e
> r) (blah a) () ()) (bleh 3 4) () (bloop a s (blop h))]  Asuume that I only
> want to find (blah (blah q w e r) (blah a) () ()).  Thanks for any response!

JS

unread,
Oct 9, 2012, 10:50:45 AM10/9/12
to qil...@googlegroups.com
That's kind of funny. I was just looking at how to do this the other
day. You can't do it with a regular expression because it's recursive.
But it's straightforward to do it algorithmically.

Here's a description of the algorithm:

http://stackoverflow.com/questions/524548/regular-expression-to-detect-semi-colon-terminated-c-for-while-loops/524624#524624

shaun gilchrist

unread,
Oct 10, 2012, 3:09:47 PM10/10/12
to qil...@googlegroups.com
Yeah even the most succinct perl utilizes "special" regex magic for keeping track of depth. 

On Wed, Oct 10, 2012 at 12:46 PM, Jacob <submissio...@gmx.com> wrote:
Thanks for the responses, I will look into that algorithm.  I had come up with my own and it worked but I wondered if regular expressions could do it more succinctly.


On Monday, October 8, 2012 7:46:10 PM UTC-4, Jacob wrote:
After all the talk of regular expression earlier, I figured I would ask this question here.  I would like to know how to use a regular expression to find the closing paranthesis of an sexp.  Such as...  [(blah (blah q w e r) (blah a) () ()) (bleh 3 4) () (bloop a s (blop h))]  Asuume that I only want to find (blah (blah q w e r) (blah a) () ()).  Thanks for any response!

--
You received this message because you are subscribed to the Google Groups "Qilang" group.
To view this discussion on the web visit https://groups.google.com/d/msg/qilang/-/ihZN9AariJgJ.

To post to this group, send email to qil...@googlegroups.com.
To unsubscribe from this group, send email to qilang+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/qilang?hl=en.

Mark Tarver

unread,
Oct 14, 2012, 5:08:38 AM10/14/12
to Qilang
Eric's work is at

https://github.com/vasil-sd/shen-libs/blob/master/regexp/regexp.shen

but I can find no doc. Anybody else find any?

Mark

Mark Tarver

unread,
Oct 14, 2012, 5:12:06 AM10/14/12
to Qilang
There is this in the commentary in the source. Is Eric using a Perl
convention?

Mark

*** Commentary:

This library implements regular expressions for Shen. String regular
expressions are compiled to Shen functions which accept a string
argument
and return an re-state object.

See the bottom portion of this file for external functions which may
be
used as an access point for compiling and using regular expressions.

Some examples are included below.

Character classes.

(1-) (match-strings (re-search "[:digit:]+" "Lorem ipsum dolor sit,
26."))
["26"]

(2-) (match-strings (re-search "\\d+" "Lorem ipsum dolor sit, 26."))
["26"]

(3-) (match-strings (re-search "\\w+" "Lorem ipsum dolor sit amet,
26, mattis eget."))
["Lorem"]

Alternatives grouped with [...]'s.

(4-) (match-strings (re-search "d[olr]+" "Lorem ipsum dolor sit,
26."))
["dolor"]

Nested regular expressions and alternatives with (...|...).

(5-) (do-matches (/. X (hd (match-strings X))) "(ipsum|eget)"
"Lorem ipsum dolor sit amet, 26, mattis eget.")
["ipsum" "eget"]

Finally it is also possible to express regular expressions using S-
exprs rather
than strings, for example

(1-) (match-strings (re-search [: d [+ [| o l r]]] "Lorem ipsum
dolor sit, 26."))
["dolor"]

The syntax for S-expr regular expressions is as follows.
[: ...] ---------------- consequtive regular expressions
[| ...] ---------------- regular expression alternatives
[* ...] and [+ ...] ---- repeating regular expressions
[*? R1 R2] ------------- compile R1 as a lazy regular expression
followed by R2

*** Code: *\
Reply all
Reply to author
Forward
0 new messages