Question: I have a small, simple, website on which I offer 40 different items with the same pricing structure. I have created a hosted paypal add-to-cart button with that pricing structure, and a dummy "Item Name" and "Item ID".

I then generate an html page for each item that contains a form reference to the hosted button, but adds hidden variables passing the item\_name and item\_number of the individual item. 

The passed item\_name variable successfully overwrites the dummy 'item name' from the hosted button when appearing in the paypal shopping cart, but the passed item\_number variable does not overwrite the dummy 'item id' in the button. I do not see an item\_id variable in the HTML Variables documentation.

It seems logical that I should be able to overwrite 'item id' if I can overwrite 'item\_name', but if the item\_number variable doesn't do it, what does?

Answer: 
Your regrex is as follows.

```
~                 // delimiter
\d+               // 1 or more numbers
[.]               // a period
[\s]*             // 0 or more whitespace characters
[A-Z]{1}          // 1 upper case letter
[A-Za-z0-9\s-\']+ // 1 or more characters, from the character class
~                 //delimiter

```

Comparing that to the string "2.bon jovi" You have:

```
~                 //
\d+               // "2"
[.]               // "."
[\s]*             // ""
[A-Z]{1}          // <- NO MATCH
[A-Za-z0-9\s-\']+ // 
~                 // 

```

"bon" does not start with a captial letter, it therefore does not match `[A-Z]{1}`

Cleaner regex
-------------

There are a few simple things you can do to clean up your regex

* don't use character-classes for one character
* don't specify `{1}` it's the same as not being present

Applying the above to your existing regex you get:

```
$pattern = "~\d+\.\s*[A-Z][A-Za-z0-9\s-']+~";

```

Which is slightly easier to read.
Your `[A-Z]{1}` sub-pattern requires one capital letter, so `"2.bon jovi - it's my life"` will not match.

And you need to escape the `-` in the `[A-Za-z0-9\s-']` character class, or put it at the start or end, otherwise it is specifying a range.

```
"~\d+\.[A-Za-z0-9\s'-]+~"

```

As pointed out in the comments, it is actually not necessary to escape the `-` in the character class in your regex. That is only because you happened to precede it with a metacharacter `\s` that cannot be part of a range. Normally, if you want to match a literal `-` and you have it in a character class, you must escape it or position it as described above.