Question: How would I create a polynomial function using an array? Basically I want to display the polynomial (ex. x^2 + 3x + 5). Then, I want to show what the highest polynomial degree is. For example, x^2 + 3x + 5 = 2 (highest degree).

Answer: 
The first `.*` is too greedy and matches too much (everything up to `x` - because `\d*` allows for an empty string to be matched). You can use non greedy `.*?`:

```
^.*?(?<width>\d*)x(?<height>\d*).*$

```

Alternatively, match non-digits in the first part:

```
^[^\d]*(?<width>\d*)x(?<height>\d*).*$

```

If the width is always preceded by `(`, you can just specify it:

```
^.*\((?<width>\d*)x(?<height>\d*).*$

```

There's multiple possibilities here and it all depends on the strings that you try to match. It's hard to say from only one example which approach would work best for you.
Thats because your first .\* is greedy and captures everything until the x, since you allow 0-n digits.

So I see two fast replacements:

```
^\D*(?<width>\d*)x(?<height>\d*)\D*$

```

would search for non-Digits before the width

you can also do

```
^.*?(?<width>\d*)x(?<height>\d*).*?$

```

which would be a non-greedy search.

Check this attempt on <https://regex101.com/r/lD7aA0/1>