|
Prev: repeated XMLHttpRequest GETs and displaying result
Next: FAQ Topic - Why does K = parseInt('09') set K to 0? (2008-06-26)
From: gentsquash on 25 Jun 2008 18:31 In a setting where I can specify only a JS regular expression, but not the JS code that will use it, I seek a regexp component that matches a string of letters, ignoring case. E.g, for "cat" I'd like the effect of ([Cc][Aa][Tt]) but without having to have many occurrences of [Xx]. Secondly, what is an efficient regexp that matches a string exactly when ALL words in a certain list occur in the string. I'd like the effect of (cat.*nip|nip.*cat) except that there are N words rather than just the two words "cat" and "nip". (I can assume that no word in the list is a prefix of any other.) Naturally, I'm looking for a regexp-solution that does not involve listing all N factorial many orderings. --Jonathan LF King, Mathematics dept, Univ. of Florida
From: Dr J R Stockton on 26 Jun 2008 08:52
In comp.lang.javascript message <6aa0c1c4-b785-4da1-9107-b681df097261(a)c5 8g2000hsc.googlegroups.com>, Wed, 25 Jun 2008 15:31:37, gentsquash(a)gmail.com posted: >In a setting where I can specify only a JS regular >expression, but not the JS code that will use it, I seek >a regexp component that matches a string of letters, >ignoring case. E.g, for "cat" I'd like the effect of > > ([Cc][Aa][Tt]) > >but without having to have many occurrences of [Xx]. If all else fails, read the manual. There are links in <URL:http://www. merlyn.demon.co.uk/js-valid.htm>. Note that the average intellectual level of those who post with @gmail addresses is so low that readers may kill-file it /in toto/. > Secondly, what is an efficient regexp that matches a >string exactly when ALL words in a certain list occur in >the string. I'd like the effect of > > (cat.*nip|nip.*cat) > >except that there are N words rather than just the two >words "cat" and "nip". (I can assume that no word in the >list is a prefix of any other.) Naturally, I'm looking for >a regexp-solution that does not involve listing all > N factorial >many orderings. I doubt whether one exists to do a direct match, at least if it is to be compatible with any user agent that knows RegExps. But one could use S2 = S1.replace(/cat|nip/gi, "") and see whether the difference of the lengths matches the total of the strings, provided that no string can occur more than once and matchable strings cannot overlap. > --Jonathan LF King, Mathematics dept, Univ. of Florida DSS. -- (c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME. Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links. Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036) Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036) |