Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: Regular expression Date: Sun, 15 Mar 2015 21:38:18 +0000 Organization: A noiseless patient Spider Lines: 23 Message-ID: <877fuindpx.fsf@bsb.me.uk> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="12086"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18XMxX3nusczDsDRCl/wSbirGaxuPWvzzA=" Cancel-Lock: sha1:M8cWn4YbHJur/BBz5QbGeGSAdBo= sha1:PfgpYsjTiVbRQQFfpWTgqzYkrGk= X-BSB-Auth: 1.29233f72adf323c7374a.20150315213818GMT.877fuindpx.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:27056 "Tony Johansson" writes: > Can somebody explain this regular expression replace(/([bcdfghjklmnpqrstvwxz])o\1/gi, '$1'); Match any one of bcdfghjklmnpqrstvwxz -- that's what the []s mean. I.e. match a single non-vowel (taking y to be a vowel too). Remember this matched letter -- that's what the ()s mean. Match a single 'o'. Match the non-vowel seen before -- that's what the \1 means. Do this globally (i.e. repeat for very match) -- that's the 'g' -- and ignoring case -- that's the 'i'. For every such match, replace it with the single-letter non-vowel. '$1' in a replacement string means the first captured match. -- Ben.