Jump to content

some questions about metacharacters.. and their usage


dsaba

Recommended Posts

yay! finally the question/s you've been waiting for!

-It's not too specific on "how do I fix bla bla, in my own specific project..bla bla"

-Its general enough to help onlookers on regex questions in general

--------------------------------------------------------------------------------------

I want to match something like this:

<meta name="stapler" content="Whatever 39.32" />

 

the part that will change that I cannot take literally will be the "39.32"

So you can basically think of it like this:

literal text - any number of chars less than 50 - literal text

 

sounds pretty easy right? I thought so too. Here's my attempt:

$pattern = "~literal text .+{1,50} literal text~";

 

all I want to say is match any characters and 50 or less of them

 

i've seen it written this way before:

(.*?){0,200}

the dot means 1 single char of any kind

the asterisk means 0 or more of these characters

and the question mark means optional of these characters, meaning it can be 0??

 

instead of putting the ? mark there why not just leave it as:

(.*)  -- I mean doesn't the 0 or more part basically say its optional too? Since there can be 0

 

 

I don't quite get the brackets either if someone could explain, when and when not to use them, i tried saying: .*{0,50}

but this gave some repitition error..etc..

 

 

-thanks

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.