Welcome to WebmasterWorld Guest from 54.226.183.49

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Interesting Regular Expression

     

ryan_b83

5:08 pm on Nov 15, 2007 (gmt 0)

5+ Year Member



Hello, I am stuck trying to come up with a regular expression to validate, and then grab out into an array of the following data structure. I did not build this data structure but I am trying to work with it. Any ideas?

THE FORMAT OF THE DATA:
Label "option1" "option2" "option3"

The Label is the first element of this and is not enclosed in quotes, the individual options however are enclosed in quotes.

So i need to validate that the user entered the data in this format with unlimited "options"

The second part would be to at a later time get this data and put it into an array with the "Label" as the [0] element of an array to make an array like this.

$array[0] == "Label"
$array[1] == "option1"
$array[2] == "option2"
$array[3] == "option3"

Thanks alot, and any ideas would really help tons!
Ryan

ryan_b83

5:58 pm on Nov 15, 2007 (gmt 0)

5+ Year Member



Nevermind, if figured it out. thanks.

^([a-z])+ (\"([a-z])+\" )+$

PHP_Chimp

9:37 pm on Nov 15, 2007 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



^([a-z])+ (\"([a-z])+\" )+$
will not match the Label "option1" etc that you posted.
As you have only specified lower case letters in your classes (so Label wont match), and there is no digits in your quoted part (so option1 wont match).

$pattern = '%([a-z]+) ("[a-z]+\d"...space in here...?)+%i'; will match what you put up. Stupid forum removing spaces...

Dont know if your problem is sorted as you are using different data to the example, or if you havent tested your work. So this may, or may not help you ;)

 

Featured Threads

Hot Threads This Week

Hot Threads This Month