Re: 4.0a3 - Two Regular Expression Libraries? -- We need your input!
- Posted by jeremy (admin) Mar 17, 2009
- 1217 views
This could be an opportunity to create a Euphoria friendly regex library.
include std/regex.e as re regex r = re:new( "\\\\" ) object result = re:find( r, "Eup\\horia" ) ? result -- { -- {4,4} -- }
This example shows how messy a regular expression can getsearching for just one character. The problem is that \ is an escape character in both the regex and the string you are searching. If you provide a regex-library that uses, say ~ , as an escape character then a regex should become much easier to read.
For those that like Perl, then a wrapped Perl library could be obtained from the archive.
This problem will occur with a wrapped PCRE as well, it has to deal with how Euphoria does the string escaping, not really the regex library in use.
You could rewrite it like this:
include std/regex.e as re regex r = re:new( #/\\/ ) -- /regex/ is the standard way of doing it in Perl object result = re:find( r, "Eup\\horia" ) ? result -- { -- {4,4} -- }
The /
/ could be almost anything. BTW, the #/..../ is what many people consider a heredoc string, it allows things such as:
sequence email = #/ Hello %s, I hope this email finds you well... The Eu Dev Team / puts(1, email)
but, it has other benefits such as the above in regex's
Jeremy