javascript regex to return letters only

You can use String#replace to remove all non letters from input string:

var r = 'AA18'.replace(/[^a-zA-Z]+/g, '');
//=> "AA"

You're confused about what the goal of the other question was: he wanted to check that there were only letters in his string.

You need to remove the anchors ^$, who match respectively the beginning and end of the string:

[a-zA-Z]+

This will match the first of letters in your input string.

If there might be more (ie you want multiple matches in your single string), use

sequence.match(/[a-zA-Z]+/g)

This /[^a-z]/g solves the problem. Look at the example below.

function pangram(str) {
    let regExp = /[^a-z]/g;
    let letters = str.toLowerCase().replace(regExp, '');
    document.getElementById('letters').innerHTML = letters;
}
pangram('GHV 2@# %hfr efg uor7 489(*&^% knt lhtkjj ngnm!@#$%^&*()_');
<h4 id="letters"></h4>

Your main issue is the use of the ^ and $ characters in the regex pattern. ^ indicates the beginning of the string and $ indicates the end, so you pattern is looking for a string that is ONLY a group of one or more letters, from the beginning to the end of the string.

Additionally, if you want to get each individual instance of the letters, you want to include the "global" indicator (g) at the end of your regex pattern: /[a-zA-Z]+/g. Leaving that out means that it will only find the first instance of the pattern and then stop searching . . . adding it will match all instances.

Those two updates should get you going.


EDIT:

Also, you may want to use match() rather than exec(). If you have a string of multiple values (e.g., "A01, B02, C03, AA18"), match() will return them all in an array, whereas, exec() will only match the first one. If it is only ever one value, then exec() will be fine (and you also wouldn't need the "global" flag).

If you want to use match(), you need to change your code order just a bit to:

var matches = sequence.match(/[a-zA-Z]+/g);

To return an array of separate letters remove +:

var matches = sequence.match(/[a-zA-Z]/g);