Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 30th, 2011, 03:34 PM
pgrinPDT's Avatar
pgrinPDT pgrinPDT is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2008
Posts: 576 pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 6 h 23 m 43 sec
Reputation Power: 180
Why doesn't prag_match find "<a"?

Alright, I haven't done much regex in my work which hasn't really been needed in my projects and when it has I just copy and paste regex for what is needed. But I ran in to a simple problem when testing some regex and I'm wondering what is causing it. In php if I do this

PHP Code:
 $word "<a";
$pattern '/<a/';

preg_match($pattern,$word,$matches);

print_r($matches); 


This shows up as blank. If I change $word and $pattern to "<>" or "<" or "a" it will find a match.

Is there something special about the "<" symbol in regex?

Reply With Quote
  #2  
Old November 30th, 2011, 04:21 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,717 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 7 h 21 m 39 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
If I run that exact code I get the right results...

Reply With Quote
  #3  
Old November 30th, 2011, 05:17 PM
pgrinPDT's Avatar
pgrinPDT pgrinPDT is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2008
Posts: 576 pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 6 h 23 m 43 sec
Reputation Power: 180
Quote:
Originally Posted by requinix
If I run that exact code I get the right results...


That's what I don't understand. Can you think of anything that can be causing this in my configuration? I've tried it 50 times and $matches shows up empty. If I try any of those other combinations I get the right result.

It only happens if I have a "<" that starts off the prag_match. If I do "<a>" it shows up blank also. But if I do "<>" it will find a match. Any thoughts?

Reply With Quote
  #4  
Old November 30th, 2011, 06:26 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,717 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 7 h 21 m 39 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Are you saying you've tried the code you posted, character for character, and are getting bad results? What's your exact code?

Reply With Quote
  #5  
Old November 30th, 2011, 06:29 PM
pgrinPDT's Avatar
pgrinPDT pgrinPDT is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2008
Posts: 576 pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 6 h 23 m 43 sec
Reputation Power: 180
Yea, this is definitely weird. It has something to do with the "<". I also tried the following and one matches the whole string and the other matches just the first letter.

PHP Code:
 $word "a<b>";
$pattern "/a<b>/";

preg_match($pattern,$word,$matches);

print_r($matches);
//Array shows up Array([0]=> a) 


So that just reads the letter a

If I do this, it shows up with a correct match

PHP Code:
 $word "ab>";
$pattern "/ab>/";

preg_match($pattern,$word,$matches);

print_r($matches);
//Array shows up Array([0]=> ab>) 

Reply With Quote
  #6  
Old November 30th, 2011, 06:31 PM
pgrinPDT's Avatar
pgrinPDT pgrinPDT is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2008
Posts: 576 pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 6 h 23 m 43 sec
Reputation Power: 180
Quote:
Originally Posted by requinix
Are you saying you've tried the code you posted, character for character, and are getting bad results? What's your exact code?


That is my exact code. I have tried it every way possible, and it shows up blank every time.

Reply With Quote
  #7  
Old November 30th, 2011, 06:54 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,717 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 7 h 21 m 39 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
...

You are looking at the HTML source of the page, right?

Reply With Quote
  #8  
Old November 30th, 2011, 07:11 PM
pgrinPDT's Avatar
pgrinPDT pgrinPDT is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2008
Posts: 576 pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level)pgrinPDT User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 6 h 23 m 43 sec
Reputation Power: 180
Quote:
Originally Posted by requinix
...

You are looking at the HTML source of the page, right?


Ahhhh... I am an idiot, lol!!

Thanks requinix

Reply With Quote
  #9  
Old December 19th, 2011, 05:27 PM
ragax's Avatar
ragax ragax is offline
Turn left at the third duck
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2011
Location: Nelson, NZ
Posts: 93 ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 24 m 37 sec
Reputation Power: 92
To complete the answer in case someone else is on the same track. This is a common phenomenon when pregmatching html and outputting it to the page to test the expression.

The easy fix is to use htmlentities.
So here, something like:
PHP Code:
echo htmlentities($matches)."<br />"

Reply With Quote
  #10  
Old December 20th, 2011, 08:26 AM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
Likely to be eaten by a grue.
Dev Shed God 10th Plane (9500 - 9999 posts)
 
Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 9,811 ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)  Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 2 Months 3 Weeks 19 h 13 m 52 sec
Reputation Power: 6112
$matches is an array in this case, so you'll have to use:
PHP Code:
echo htmlentities(print_r($matches,1))."<br />\n"
__________________
HEY! YOU! Read the New User Guide and Forum Rules

"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

Reply With Quote
  #11  
Old December 20th, 2011, 11:19 PM
ragax's Avatar
ragax ragax is offline
Turn left at the third duck
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2011
Location: Nelson, NZ
Posts: 93 ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level)ragax User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 24 m 37 sec
Reputation Power: 92
Spot on.
Thanks for pointing that out, I didn't pay enough attention to the details.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Why doesn't prag_match find "<a"?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap