Preg_match, I'm lost

I am looking to setup a preg_match for a string that follows the following structure:

  1. must start and end with alphanumeric characters (can repeat - ex. aaabbb)
  2. can contain alphanumeric (can repeat - ex. bbb666)
  3. can contain a period, space, apostrophe or hyphen (non repeating but can have one of each)

‘one–tw’'o- is invalid
o’ne-two three. - is valid

My last try:
^[a-z0-9]+(?:[ '.-][a-z0-9]+)*$/i - only alpha numeric is valid

Thanks

The following seems to work, except that it only allows hyphens, I also need the apostrophe and a period. The period must be followed by a space.

I have fiddled around for way to long and just not getting the right syntax.

/^[A-Za-z0-9 ]+(?:-[A-Za-z0-9 ]+)?$/D

Thanks

Would something like this do it.

/^([A-Za-z0-9 ]+(?:-[A-Za-z0-9 ]+)?(. )?)*$/g

Sponsor our Newsletter | Privacy Policy | Terms of Service