Picking characters uniquely in a multiple string

5

Hello, I need a help for a regular expression that satisfies some occurrences of a text file.

In this case, I need a regular expression that finds occurrences where there are a minimum number of characters in a pattern. For example:

I have the following string: "'C'; 'AEBDCEAB'; 'A'; 'B'" ...

In this case, I want to get only the characters of "AEBDEAB" , so that I can use each (in this case, the grouping is for each character, not the whole group, as in a /[A-E]/ ) .

    
asked by anonymous 18.03.2014 / 17:40

2 answers

3

Guilherme, try this:

var str = "'C'; 'AEBDCEAB'; 'A'; 'B'";
var resultado = str.match("[a-zA-Z]{8}");

I used the match .

This will give an array where you can get what you want using resultado[0] . If you want each letter of this group you can use resultado[0].split('')

Example

If this group appears several times you can use:

var str = "'C'; 'AEBDCEAB'; 'A'; 'B' 'AEBFCEAB' 'AEBXCEAB'";
var resultado = str.match(/[a-zA-Z]{8}/g);
console.log(resultado); // dá ["AEBDCEAB", "AEBFCEAB", "AEBXCEAB"] 

Example

    
18.03.2014 / 18:36
0

This regular expression matches a minimum of 8 characters, a-zA-Z characters:

[[:alpha:]]{8,}

or

[a-zA-Z]{8,}
    
18.03.2014 / 19:09