Devilzc0de Forum Follow @devilzc0de
  • Home
  • Hacking
  • Networking
  • Programming
  • O.S
  • Server
  • Tweets
  • Search
  • Member List
  • Calendar
Current time: 05-21-2013, 02:54 PM Hello There, Guest! (Login — Register)
Devilzc0de Forum › Information Technology › Programming › PHP v
« Previous 1 ... 20 21 22 23 24 ... 31 Next »

[Ask] Regex help

Home General Computer Multimedia Business Lounge

Post Reply 
Tweet
Threaded Mode | Linear Mode
Ask Regex help
12-14-2011, 11:13 PM
Post: #1
kalakhan Offline
./Devilz 1st Cadet
Posts: 1
Joined: Nov 2010
Reputation: 0
Question Regex help
guys ,

what is the compatible regex to find link like this ...

http://yoursite.com/site/news.php?gid=10

http://yoursite.com/site/news.php?gid=2

https://yoursite.com/site/news.php?gid=
Find all posts by this user
Quote this message in a reply
12-15-2011, 01:41 AM (This post was last modified: 12-15-2011 01:43 AM by ketek.)
Post: #2
ketek Offline
bocah ingusan
*******
Administrators
Posts: 2,168
Joined: Jan 2010
Reputation: 369
RE: Regex help
if you want to just find links like that, test it with this one
Code:
https?\:\/\/([a-zA-Z0-9]*\.)+[a-zA-Z0-9]+(\/[^\/?]*)+\?[^\s]*
Find all posts by this user
Quote this message in a reply
12-16-2011, 08:38 PM (This post was last modified: 12-16-2011 08:39 PM by darkslayer.)
Post: #3
darkslayer Offline
./Devilz Advisor
Posts: 570
Joined: May 2010
Reputation: 38
RE: Regex help
(12-15-2011 01:41 AM)ketek Wrote:  if you want to just find links like that, test it with this one
Code:
https?\:\/\/([a-zA-Z0-9]*\.)+[a-zA-Z0-9]+(\/[^\/?]*)+\?[^\s]*

PHP Code:
<?php
$url
=array("http://yoursite.com/site/news.php?gid=10","http://yoursite.com/site/news.php?gid=2","https://yoursite.com/site/news.php?gid=");
foreach(
$url as $x){
if(
preg_match("/http:\/\/yoursite.com\/site\/news.php?gid=10/",$x)){echo "$x >> TRUE<br>";}else{echo "$x >> FALSE<br>";}
}
?>
output
Code:
http://yoursite.com/site/news.php?gid=10 >> FALSE
http://yoursite.com/site/news.php?gid=2 >> FALSE
https://yoursite.com/site/news.php?gid= >> FALSE

cant u tell me why no 1 output is FALSE?
Find all posts by this user
Quote this message in a reply
12-17-2011, 06:43 PM (This post was last modified: 12-17-2011 07:02 PM by ditatompel.)
Post: #4
ditatompel Offline
Administrator
*******
Administrators
Posts: 2,168
Joined: Dec 2010
Reputation: 367
RE: Regex help
(12-16-2011 08:38 PM)darkslayer Wrote:  
PHP Code:
<?php
$url
=array("http://yoursite.com/site/news.php?gid=10","http://yoursite.com/site/news.php?gid=2","https://yoursite.com/site/news.php?gid=");
foreach(
$url as $x){
if(
preg_match("/http:\/\/yoursite.com\/site\/news.php?gid=10/",$x)){echo "$x >> TRUE<br>";}else{echo "$x >> FALSE<br>";}
}
?>
output
Code:
http://yoursite.com/site/news.php?gid=10 >> FALSE
http://yoursite.com/site/news.php?gid=2 >> FALSE
https://yoursite.com/site/news.php?gid= >> FALSE

cant u tell me why no 1 output is FALSE?

Wrong regex on preg_match
PHP Code:
if(preg_match("/http:\/\/yoursite.com\/site\/news.php?gid=10/",$x)){echo "$x >> TRUE<br>";}else{echo "$x >> FALSE<br>";} 
The characters that you SHOULD escape are:
Code:
* + ? . ( ) [ ] { } / | ^ $
Just like Perl, the preg functions allow any non-alphanumeric character as regex delimiters.
Unlike C# or Java, PHP does not require all backslashes in strings to be escaped. If you want to include a backslash as a literal character in a PHP string, you only need to escape it if it is followed by another character that needs to be escaped.

if you want to ouse Ketek pregmatch it should be like this :
PHP Code:
if(preg_match("/https?\:\/\/([a-zA-Z0-9]*\.)+[a-zA-Z0-9]+(\/[^\/?]*)+\?[^\s]*/i",$x)) {
    echo 
"$x >> TRUE<br>";
}
else {
    echo 
"$x >> FALSE<br>";
} 
Find all posts by this user
Quote this message in a reply
12-17-2011, 08:46 PM (This post was last modified: 12-17-2011 08:47 PM by darkslayer.)
Post: #5
darkslayer Offline
./Devilz Advisor
Posts: 570
Joined: May 2010
Reputation: 38
RE: Regex help
(12-17-2011 06:43 PM)ditatompel Wrote:  The characters that you SHOULD escape are:
Code:
* + ? . ( ) [ ] { } / | ^ $
Just like Perl, the preg functions allow any non-alphanumeric character as regex delimiters.
ouch.. thanx bro
Quote:if(preg_match("/http:\/\/yoursite.com\/site\/news.php\?gid=10/",$x)){echo "$x >> TRUE<br>";}else{echo "$x >> FALSE<br>";}
i dont know if (?) or non-alphanumeric it must be escaped.
thanx

back to topic
i dont know what kalakhan's example mean

if he mean like this
PHP Code:
asdasdas
 asdasdas 
adsadad 
http
://yoursite.com/site/news.php?gid=10 >>this
adasd 
http
://example.com/wow/me.php?xx=2 >>this
asdadhsdjas 
https
://rtfhyujokp.com/tfguhjk/rtyuhjokl.php?tyuo= >>this 
it should use ketek's regex example

but if he mean like this
PHP Code:
http://rftk.com/swdfghjkl/defrgtyhujkl.php?sdtfyh=10
https://dtfyguhjokl.com/drftghnews.php?gid=
http://yoursite.com/site/news.php?gid=10 >>this
http://yoursite.com/site/news.php?gid=2 >>this
https://yoursite.com/site/news.php?gid= >>this 
he should use regex like this
PHP Code:
"/[(http)|(https)]:\/\/yoursite.com\/site\/news.php\?gid=[0-9]?/" 
am i wrong?
Find all posts by this user
Quote this message in a reply
« Next Oldest | Next Newest »
Post Reply 


Topic Tools
Topic Link :
BBCode :
HTML Code :
View a Printable Version Send Thread to a Friend Subscribe to this thread
Submit Google Submit Face book Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Jeqq

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  [Tutor] [share]Pengenalan Dasar-Dasar Regex RieqyNS13 15 244 05-02-2013 09:24 PM
Last Post: CodeSearcher
  [Solved] [solved]regex with multiple line darkslayer 0 348 10-14-2011 08:06 PM
Last Post: darkslayer

Users Browsing
1 Guest(s)

  • Contact Us
  • devilzc0de
  • Return to Top
  • Mobile Version
  • RSS Syndication
  • Help
Current time: 05-21-2013, 02:54 PM Powered By MyBB, © 2002-2013 MyBB Group. Theme created by Justin S. | Mixed By Chaer.Newbie | Fixed By Aditya

USING THIS SITE INDICATES THAT YOU HAVE READ AND ACCEPT OUR TERMS. IF YOU DO NOT ACCEPT THESE TERMS, YOU ARE NOT AUTHORIZED TO USE THIS SITE