Jump to content

Need help regarding pattern matching


sree4u

Recommended Posts

Dear All,

I have a log file by the name of 192.168.229.128.log which has a particular pattern available like /opt/lampp/htdocs/enroll/192.168.229.128/.  I want to check this pattern from this file and do some activities.

 

the pattern matching i am giving is :-

 

preg_match("/opt\/lampp\/htdocs\/enroll\/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\\\/", "$theData", $matches)

 

Attached herewith is the log file and the source code.

 

Please help to resolve this issue.

 

Regards,

Sreejith

a.php

1.txt

Link to comment
Share on other sites

1) You have not stated a problem. What are you trying to accomplish; what is happening that should NOT happen; what is NOT happening that SHOULD happen.

 

2) Turn on error_reporting (in Development) so PHP will give you some help finding problems

 

3) I (personally) do NOT download attachments, and I'm sure a lot of others don't either. Post the pertinent code -- using

 ... 

tags

 

 

preg_match("/opt\/lampp\/htdocs\/enroll\/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\\\/", "$theData", $matches)

 

4) Since you need slashes in the regular expression, choose a different delimiter so you don't have to keep escaping them:

preg_match("~opt/lampp/htdocs/enroll/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\\/", "$theData", $matches)

I always use the tilde, since it is rarely in anything I would be searching.

 

5) In making that change, it appears that there is no closing delimiter on your expression; and why are you putting a backslash at the end of it? Or did you just keep adding "\" until it "looked right"?

 

It looks like you want the literal slash ("/") as part of the expression at the beginning and the end. The preg_ family of functions require a delimiter around the regular expression. So the first and last characters have to be the same and are NOT part of the expression. (Then, there can be modifiers after the closing delimiter)

 

preg_match("~/opt/lampp/htdocs/enroll/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/~", "$theData", $matches)
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.