Jump to content

Check first character matches the last character in a string


HuggieBear

Recommended Posts

Morning all,

I have the following expression which I think works well.  What I want in short is a string to start and end with the same character, with atleast one thing in between.

[code=php:0]/^(.).+\1$/
[/code]

Below is the details of what I think the above does, but wondered if there's a better way to do it...

1. Start at the beginning of the line
2. Capture the first character, doesn't matter what it is
3. Then there has to be another character, again, doesn't matter what, but has to be atleast one
4. Then an identical character to the first
5. Then the end of the line

Regards
Huggie
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.