Belgin Fish
Belgin Fish

Reputation: 19847

Regex for single letter with dot after and stuff around? php

I have the following being stored in a variable

>a.<

>b.<

>c.<

but there's a bunch of other stuff around it, what regex would I use to match

>(.*).<

where (.*) is any single letter?

Upvotes: 0

Views: 54

Answers (2)

waldol1
waldol1

Reputation: 1881

Try using this regular expression: \>([a-zA-Z])\.\<

The dot is a control character that must be escaped. The [] specifies a range for a single character.

EDIT:

These characters needs to be escaped: . \ + * ? [ ^ ] $ ( ) { } = ! < > | : - according to http://php.net/manual/en/function.preg-quote.php. I have updated my answer to reflect that.

Upvotes: 3

NeverHopeless
NeverHopeless

Reputation: 11233

You can also try this pattern:

>[^\.]+\.<

Independent of any specific character (other than last dot), just in the same way as yours.

Upvotes: 1

Related Questions