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 may use the following expression:

```
/^[\w\s]*:\d+-\d+(?:;[\w\s]*:\d+-\d+)*;?$/

```

See the [regex demo](https://regex101.com/r/yIZmwq/2)

**Details**:

* `^` - start of string
* `[\w\s]*` - zero or more word or whitespace chars
* `:` - a colon
* `\d+-\d+` - 1 or more digits, `-` and again 1 or more digits
* `(?:;[\w\s]*:\d+-\d+)*` - 0 or more sequences of:
	+ `;` - a semi-colon
	+ `[\w\s]*:\d+-\d+` - the pattern described above
* `;?` - 1 or 0 `;`
* `$` - end of string.

Note that `[\w\d]` matches the same text as `\w`,thus, I suggest removing `\d` from `[\w\s]`.
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.