Jump to content

[SOLVED] preg-match with a string and numbers


imperium2335

Recommended Posts

Hi, I can't get the expression to work for my preg_match, what I'd like is for it to match the string, but only if it is accompanied by a letter, not a number. So if a string was found with a number after it, it would pass, but fail if there where letters.

I have this but it doesn't work:

if(!preg_match("/table-/+[abcdefghijklmnopqrstuvwxyz]", $string, $dump)) {
//do stuff
}

Thanks for any help.

Can you give an example of what your expect to pass and fail

ie

A. table-12 = pass

B. table-123 = pass

C. table-1a3 = fail or pass ?

D. table-abc = fail

E. mytable-1 = fail or pass ?

 

With C/E would it pass as its "table-1" ?

What does it match up to ?

ie

name="table-12"

would match the text from " to "

hi,

 

table-24234 = pass

table-1 = pass

table-name = fail

table-cheese134 = fail

 

table- must just be "table-"

its actually checking a html tag, to expand alittle:

 

id="table-23421" as an example, but i dont want it to pass id="table-name" etc

Thanks for your reply.

Great resource is right here

 

its mainly simple ones and practice

 

ie

if (preg_match('/id="table-\d+"/', $string)) {
echo "valid"
}

finds id="table- then a \d (digit) + (means 1 or more) and then finds a "

Now if it finds the digits but then NOT a " it won't match so 12b" would fail

 

on my second example i put () around the \d+ this means capture (store in $dump) now

$dump[0] = the full matched string

$dump[1] = the first captured item

 

okay that's a break down of what you have.. hope that helps and doesn't scare you away :)

it takes time when I first saw them i was :wtf:

but they seam simpler now :)

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.