1. perl-ish regexps?
Yes, I'm back again. Be afraid, be very afraid..
I was wondering if anyone would be willing/capable of implementing perl-
like regexps, in a function called regex() or something?
Yes, I know, perl and its regexps look like line noise, but typing
result =3D regex({^\(d).?\1$}, myVar)
(and I use {} instead of // as in perl {RE} vs. /RE/)
is rather easier than the euphoria equivalent of.. well... whatever.
(The regexp in question would find a 'word' that starts with a digit and
possibly has a string of characters after it, and ends with the same digit).=
You could make the function either return the closest match, or return all
the matches if the user so desires (result should be an object?)
This could make things easier for the database (and such) inclined.
And adding the substitute function would be totally brilliant, so removing,
for example, excessive whitespace from scripts, formatting text to whatever
you want and such would be so much easier.
sequence x
x =3D "spaces a plenty"
x =3D subst({\s+}, {\s}, x)
x whould be "spaces a plenty" (unless I messed up the regexp, which of
course is highly possible).
x =3D "m5439'.e5588/#s...-*''s009989/&a785784g=B4654677,,.^^=A8=A8=A8~~e"
x =3D subst({[^a-zA-Z]}, {}, x)
x would amount to "message" (ooh! Aaaah! Uuuuuuh!)
Any thoughts on this?
Just my 0.0000341792 cents....
--Tom Ekl=F6f
DO .1 <- "^'"^.3$.3"~"#0$#3906"'$'"^.3$.3"~"#0$#3906"'"~"#0$#3906"
2. Re: perl-ish regexps?
Maybe YOU could write Pearl in Euphoria, the Linux version is only 12MEGS.
I think you would be better off finding a way to write a simple macro
processor like M4.
3. Re: perl-ish regexps?
Tom Eklvf wrote:
> I was wondering if anyone would be willing/capable
> of implementing perl-like regexps, in a function called
> regex() or something?
You might be able to hack something from my "Regular Expression Matcher",
found in the Euphoria archive. It's aimed at LEX-type expressions, but it's
not that far from what you are aiming for.
> result = regex({^\(d).?\1$}, myVar)
Try instead:
result = regex("^\\(d).?\\1$", myVar)
You need quotes {"} instead of faces {{}}, or Euphoria will try to evaluate
your expression. In addition, the backslash {\} is a poor selection in
Euphoria. It is used to delimit special characters, like
\t (tab)
\n (new line)
\r (carriage return)
\" (quote)
\' (single quote)
\\ (backslash).
> x = "m5439'.e5588/#s...-*''s009989/&a785784g4654677,,.^^(((~~e"
Same problem as above:
x = "m5439'.e5588/#s...-*\''s009989/&a785784g4654677,,.^^\(((~~e"
-- David Cuny
4. Re: perl-ish regexps?
> Maybe YOU could write Pearl in Euphoria, the Linux version is only 12MEGS.
> I think you would be better off finding a way to write a simple macro
> processor like M4.
I think you misunderstood me, I meant just the regexps, not all of perl (EPerl?
Hmm.. weird).
Cheerio
--Tom
----
Get your free email at http://www.gnwmail.com
5. Re: perl-ish regexps?
> Tom Eklvf wrote:
>
> > I was wondering if anyone would be willing/capable
> > of implementing perl-like regexps, in a function called
> > regex() or something?
>
> You might be able to hack something from my "Regular Expression Matcher",
> found in the Euphoria archive. It's aimed at LEX-type expressions, but it's
> not that far from what you are aiming for.
>
> > result = regex({^\(d).?\1$}, myVar)
>
> Try instead:
>
> result = regex("^\\(d).?\\1$", myVar)
>
> You need quotes {"} instead of faces {{}}, or Euphoria will try to evaluate
> your expression. In addition, the backslash {\} is a poor selection in
> Euphoria. It is used to delimit special characters, like
>
> \t (tab)
> \n (new line)
> \r (carriage return)
> \" (quote)
> \' (single quote)
> \\ (backslash).
>
> > x = "m5439'.e5588/#s...-*''s009989/&a785784g4654677,,.^^(((~~e"
>
> Same problem as above:
>
> x = "m5439'.e5588/#s...-*\''s009989/&a785784g4654677,,.^^\(((~~e"
>
> -- David Cuny
----
Get your free email at http://www.gnwmail.com
6. Re: perl-ish regexps?
- Posted by Mathew Hounsell <mfh03 at UOW.EDU.AU>
Jul 19, 1999
-
Last edited Jul 20, 1999
Tom Elkof,
Regular Expressions are a good thing to have, however they are difficult
to evaluate.
Unfortunately Dave's library had faults and did not evaluated all
expresions properly.
One of my computer science lecturers suggested using a tree.
I suggest finding a standard algorithm and writing it in euphoria.
I have not gotten round to finding one, there is probabely one in the
uni library.
I wanted one to add lex features to a euphoria language builder.
-------------------------
Sincerely,
Mathew Hounsell
mat.hounsell at excite.com