Question: I'm trying to write a function that will return true if its input string matches a pattern and false if it doesn't. Sounds like a job for a regex to me.

The pattern is: `<something>:<number>-<number>;`

where `<something>` can be any combination of letters or numbers or blank. The pattern can repeat any number of times in the input string, and the `;` is optional for the last repetition of the pattern.

So these would return true:

* ABC:1-2;CDE:3-4
* ABC:1-2;CDE:3-4;
* ABC:1-2
* :1-2

but these would return false:

* ABC:1-2;cats;CDE:3-4
* ABC:1-2;CDE:3-4;cats

I've gotten that one repetition of the pattern could be represented with

`[\w\d\s]*:\d+-\d+;?`

but I'm struggling to find how to determine if the entire string is made up ONLY of repetitions of that pattern. 

I've tried several things, including surrounding the pattern with `( )+` and/or `^ $`, but keep running into issues. What's the best way to check if a string is composed only of a pattern, repeated one or more times, in JavaScript?

Answer: 
You can use this simpler regex:

```
/^(?:[a-zA-Z0-9]*:\d+-\d+(?:;?$|;))+$/

```

[RegEx Demo](https://regex101.com/r/dKC9j9/2)

We keep trailing `;` optional at the end of each set which is:

`[a-zA-Z0-9]*:\d+-\d+;?` this matches 0 or more alphanumerics followed by `:` followed by digits-hyphen-digits.
You need to use + quantifier. Try the next approach:

```
function test(str) {
    return /^([\w\s]*:\d+-\d+;?)+$/.test(str)
  }
  console.log(test('ABC:1-2;CDE:3-4'));//true
  console.log(test('ABC:1-2;CDE:3-4;'));//true
  console.log(test('ABC:1-2'));//true
  console.log(test(':1-2'));//true
  console.log(test('ABC:1-2;cats;CDE:3-4'));//false
  console.log(test('ABC:1-2;CDE:3-4;cats'));//false

```