From: "Mauricio Fernández" Date: 2003-04-16T07:28:44+09:00 Subject: Re: regular expressions On Wed, Apr 16, 2003 at 07:18:43AM +0900, Chris Pine wrote: > Then I started thinking: We have Perl-style regexps, right? What other > style regexps are there? I'm sure people have come up with a number of > different ideas, but a quick Google didn't turn up anything. Does anyone > know of any other ideas? It seems to me you might like this: http://mywebpages.comcast.net/mdschneider/ruby/index.html#REGTREE Example: # string to match url_string = "myWebPages.comcast.net/mdschneider" # build regex word = RegexTree.init.word_char.plus_times domain_element = word.capture_array("domains") domain = (domain_element | '.').plus_times url = domain + '/' + word.cast("user") # match the string url_match = url.match(url_string) # extract the values domains = url_match.value("domains").compact user = url_match.value("user") # display puts puts "URL path extraction demo:" puts puts "url_string: #{url_string}" puts "regex generated: #{url.render}" # ==> ((?:[0-9A-Z_a-z]+|\.)+)/([0-9A-Z_a-z]+) puts "domains found: #{domains.inspect}" # ==> ["myWebPages","comcast", "net"] puts "user found: #{user.inspect}" # ==> mdschneider It all comes down to using some pseudo-EBNF notation. It is more powerful than required for regexps, and far more verbose, but then again, sometimes we just want that. -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com Look, I'm about to buy me a double barreled sawed off shotgun and show Linus what I think about backspace and delete not working. -- some anonymous .signature