Question: I just finished all the "Easy" CoderByte challenges and am now going back to see if there are more efficient ways to answer the questions. I am trying to come up with a regular expression for "SimpleSymbol". 

> 
> *(Have the function SimpleSymbols(str) take the str parameter being passed and determine if it is an acceptable sequence by either
>  returning the string true or false. The str parameter will be composed
>  of + and = symbols with several letters between them (ie.
>  ++d+===+c++==a) and for the string to be true each letter must be surrounded by a + symbol. So the string to the left would be false.
>  The string will not be empty and will have at least one letter.)*
> 
> 
> 

I originally answered the question by traversing through the whole string, when a letter is found, testing on either side to see if a "+" exists. I thought it would be easier if I could just test the string with a regular expression like, 

```
str.match(/\+[a-zA-Z]\+/g)

```

This doesn't quite work. I am trying to see if the match will ONLY return true if the condition is met on ALL of the characters in the string. For instance the method will return true on the string, "++d+===+c++==a", due to '+d+' and '+c+'. However, based on the original question it should return false because of the 'a' and no surrounding '+'s.

Any ideas?

Answer: 
EDIT: @Marc brought up a very good point. The easiest way to do this is to search for violations using

```
[^+][a-zA-Z]|[a-zA-Z][^+]

```

or something like it. This will find all **violations** of the rule -- times when a letter appears next to something other than a `+`. If this matches, then you can return `false`, knowing that there exist violations. Else, return `true`. 

Original answer:

Here's a regex -- I explain it below. Remember that you have to escape `+`, because it is a special character!

```
^([^a-zA-Z+]|(\+[a-zA-Z]\+)|[+])*$

^ // start of the string
[^a-zA-Z+] // any character except a letter or a + (1)
| // or
(\+[a-zA-Z]\+) // + (letter) + (2)
| //or
[+] // plus (3)
)*$ // repeat that pattern 0 or more times, end

```

* The logic behind this is: skip all characters that aren't relevant in your string. (1)
* If we have a + (letter) +, that's fine. capture that. (2)
* if we have a + all by itself, that's fine too. (3)
* A letter without surrounding `+` will fail.
```
/^[=+]*\+[a-z](?=\+)(?:\+[a-z](?=\+)|[+=]+)*$/i.test(str)

```

pattern details:

```

^                 # anchor, start of the string
[=+]*             # 0 or more = and +
\+ [a-z] (?=\+)   # imposed surrounded letter (at least one letter condition)
(?:               # non capturing group with:
    \+[a-z](?=\+) # surrounded letter 
  |               # OR
    [=+]+         # + or = characters (one or more)
)*                # repeat the group 0 or more times
$                 # anchor, end of the string

```

To allow consecutive letters like `+a+a+a+a+a+`, I use a lookahead assertion to check there is a `+` symbol after the letter without match it. (Thanks to ridgrunner for his comment)

Example:

```
var str= Array('+==+u+==+a', '++=++a+', '+=+=', '+a+-', '+a+a+');
for (var i=0; i<5; i++) {
    console.log(/^[=+]*\+[a-z](?=\+)(?:\+[a-z](?=\+)|[+=]+)*$/i.test(str[i]));
}

```