Re: Escaping text for the regular expression compiler

"Greg Compestine" <[email protected]>
Newsgroups gmane.comp.lang.eiffel.gobo.general
Message-ID <[email protected]>
Hi Paul, 

Use a regular expression to escape the special characters. The gobo
regexp engine is based on PCRE, so a lot of recipes that would work for
Perl work for it as well. In Perl, you could do what you want with
something like the following (all of this is untested code to be taken
as such):

   $foo =~ /(\(\)\.)/\\$1/g;

Which essentially says find all of the parentheses and periods and
insert '\' before them.

In Eiffel it takes a bit more.

	test is
			l_re: RX_PCRE_REGULAR_EXPRESSION
		do
			create l_re.make
			l_re.compile("(\(|\)|\.)")
			if l_re.matches ("My file(1).txt") then
				print (l_re.replace_all ("\\\1\") +
"%N")
			end	
		end

What's printedshould be an escaped version of the filename.

Handy-dandy reference on PCRE:
http://www.pcre.org/

Also, the examples for the regexp library that are in Gobo's CVS
repository are worth studying.
http://gobo-eiffel.cvs.sourceforge.net/gobo-eiffel/gobo/example/regexp/p
cre/pcre.e?view=markup

---


Paul wrote:
 
Does Gobo contain a function for escaping a STRING so it may be passed
as part of a complete expression, without being an expression itself, to
the regex parser?

As an example, take a file name: "Copy of MyFile (1).txt", the file name
is actually an expression rather than a literal. I want it to be
evaluated as a literal.

I want to be able to create an expression such as: ".+" + escape
("(1).txt") + "$"

Thanks,
Paul.


To Post a message, send it to:   [email protected]
To Unsubscribe, send a blank message to: [email protected] 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/gobo-eiffel/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/gobo-eiffel/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[email protected] 
    mailto:[email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.