Question: Given a list of divs, I need to be able to use the up and down arrow keys to navigate between items in the list, apply an `.ag-menu-option-active` class to the currently selected item, and on `Enter` key, trigger a click on the currently selected list item. 

I'm currently able to iterate over the list of items, but on down arrow, it only logs out the second item in the list. As stated above, the user should be able to move up and down the list and have the active class applied to the currently selected item. When the user hits the `Enter` key, the associated list item should be clicked.

```
let columnMenuItems = document.querySelectorAll('.ag-menu-option');
document.addEventListener('keydown', e => {
  if (e.key === 'ArrowDown') {
    for (let i = 0; i < columnMenuItems.length; i++) {
      if (columnMenuItems[i].classList.contains('ag-menu-option-active') === true) {
        console.log("MENU OPTION SELECTED: ", columnMenuItems[i + 1])
        columnMenuItems[i].click();
        break;
      }
    }
  }
});

```

**JSFiddle link: [link](http://jsfiddle.net/5anhuo0k/23/)**

Answer: 
PowerShell's "-replace" operator, which is used with regex is often confused with ".replace" method on strings. There are many way you can skin that cat, but your question is a bit vague to answer precisely. 

Regardless, in your case you do not want to use the "method" 

```
string.replace()

```

instead use, as others suggested, the "operator"

```
string -replace "regex_to_be_replaced_here", "replacement_here"

```

A couple of examples have been provided already. I would go with Joey's, where his regex says "start from the beginning of the string and match everything except a dot (".") and replace them with nothing, effectively erasing them leaving the parts after dot behind:

```
$newstring = $domain -replace '^[^.]*', ''

```

You might also be able to use .split method or -split operator

```
string.split("some_delim") or string -split "some_delim"

```

Example:

```
$domain = "random.org"    
$domain.split('.')[-1]
org

```

split operator, like -replace operator uses regex, where '.' has a special meaning, so you need to escape it, telling regex that you really want to match a '.'

```
 ($domain -split '\.')[-1]
 org

```

If you already know how many characters from the right side of the string you need, you may even use substring(). Following means give me the last 3 chars of $domain:

```
$domain.substring($domain.length - 3)
org

```
If you are seeking only the TLD (.com, .org, .gov, etc.), then you can use -replace with a capture.

```
PS C:\src\t> "www.myhome.org"  -replace '^[^.]*'
.myhome.org
PS C:\src\t> "www.myhome.org"  -replace '^.*(\..*)', '$1'
.org

```