From: James Britt Date: 2004-11-20T00:42:54+09:00 Subject: Re: Tales of the Regex (Re: About Regular Expressions) Robert Klemme wrote: > "James Britt" schrieb im Newsbeitrag > news:419CF779.2080806@neurogami.com... > > >>all substrings in a given set of substrings, irrespective of the order >>of the substrings in either the target string or the set of > > ubstrings? ) > > Yes you can, but it's going to be uuuuugly and slooooow if you have more > than two sub strings. A set of one regexp per sub string is likely to be > more efficient: > > substrings = %w{foo bar baz} > rxs = substrings.map {|s| Regexp.new(Regexp.escape(s))} > > string = "klajsd askdjkahs bar asjdajsd asdbazagdjhagsdh f0dfdfuufoosds" > puts "Got it: #{string}" if rxs.all? {|rx| rx =~ string} Thank you. I would be searching on possibly any number (but figure 5 or 6 as an average) of such substrings. The all? syntax is nice and clear. > > >>One a side note, I wonder what it would take to write a domain language, >>parable by Ruby, that let one write REs in plain-ish English? Maybe >>take some of the mystery out of regular expressions for most of the >>common cases. (Or would that just get people dependent on too much >>hand-holding?) > > > Such a language with the same expressiveness as typical regexps would be > too verbose for me. But I think I remember someone did something similar > with Ruby. Can't quite remember who it was or a mail thread subject but I > do believe someone has attempted to do something in that direction. Yes, the details were posted here the other day. I thought it would be handy for folks who have a hard time remembering certain syntax, or want the intent of the regexp to be more clear. Thanks, James > > Kind regards > > robert > > > . >