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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.