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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.