[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

Regular expression

Tony Johansson

3/15/2015 9:26:00 PM

Can somebody explain this regular expression
document.getElementById('rovarsprak').value.replace(/([bcdfghjklmnpqrstvwxz])o\1/gi,
'$1');

//tony

3 Answers

Ben Bacarisse

3/15/2015 9:38:00 PM

0

"Tony Johansson" <johansson.andersson@telia.com> writes:

> Can somebody explain this regular expression
<snip>
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.

Cezary Tomczyk

3/15/2015 10:40:00 PM

0

On 2015-03-15 22:25, Tony Johansson wrote:
> Can somebody explain this regular expression
> document.getElementById('rovarsprak').value.replace(/([bcdfghjklmnpqrstvwxz])o\1/gi,
> '$1');

The other way (apart of Ben's explanation) to explain that (and others
as well) regular expression might be to use nice tool:
https://regex101.com/...

--
Cezary Tomczyk
http://www.ct...

ram

3/16/2015 12:00:00 PM

0

"Tony Johansson" <johansson.andersson@telia.com> writes:
>Can somebody explain this regular expression
>document.getElementById('rovarsprak').value.replace(/([bcdfghjklmnpqrstvwxz])o\1/gi,
>'$1');

It is not clear what »this« refers to.

The regular expression describes a string of three characters.
First, one of "bcdfghjklmnpqrstvwxz", then "o", and, finally,
a character that is the same character as the first character.