Simple Preg Match

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
lenton
Forum Commoner
Posts: 49
Joined: Sun Jun 20, 2010 6:45 am

Simple Preg Match

Post by lenton »

I want to create a pattern which will allow this: "What is [anything here]?"
Valid example: What is an orange?

This is the pattern I have so far but it doesn't seem to be working:
"/^what is *\?$/i"

Could you please tell me what I'm doing wrong? Cheers.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Simple Preg Match

Post by Christopher »

The * means any number of the previous thing, it your case it is a space character. The . will match any character, so maybe use "/^what is .*\?$/i"
(#10850)
Post Reply