Jump to content


Photo

regular expressions


  • Please log in to reply
1 reply to this topic

#1 3rve

3rve
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 07 June 2006 - 10:55 AM

I created a script using regular expressions to pull info from text files. The script works fine on my test server , but when I upload it to my web host the regex strings do not work the same. Looking at the php info I see that my test server is php 5.04 built --with-pcre-regex=/usr' and the server api is apache 2 handler. Now on the web host it is php 5.05 built --with-mbregex and the server api is CGI. They are both Linux. Test server is apache 2.0.54 / web host is apache 1.3.36. Is there a difference in the way mbregex handles regex vs. pcre? Or maybe it is cgi. Not really sure what is going on, but any help would be greatly appreciated, thanks....

$regx = "Name: [-0-9a-zA-Z''_ ]{4,}";

On my test server this to grab ( Name: 'name' name name ) appostrophes included

But on the live server it will only match one of the apostrophes and stop where the second one is

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 07 June 2006 - 12:04 PM

[!--quoteo(post=380939:date=Jun 7 2006, 06:55 AM:name=3rve)--][div class=\'quotetop\']QUOTE(3rve @ Jun 7 2006, 06:55 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I created a script using regular expressions to pull info from text files. The script works fine on my test server , but when I upload it to my web host the regex strings do not work the same. Looking at the php info I see that my test server is php 5.04 built --with-pcre-regex=/usr' and the server api is apache 2 handler. Now on the web host it is php 5.05 built --with-mbregex and the server api is CGI. They are both Linux. Test server is apache 2.0.54 / web host is apache 1.3.36. Is there a difference in the way mbregex handles regex vs. pcre? Or maybe it is cgi. Not really sure what is going on, but any help would be greatly appreciated, thanks....

$regx = "Name: [-0-9a-zA-Z''_ ]{4,}";

On my test server this to grab ( Name: 'name' name name ) appostrophes included

But on the live server it will only match one of the apostrophes and stop where the second one is
[/quote]

first off, i have to ask why you have two apostrophes in your regex anyway. when you're doing a character grouping like that, you only need it once. the second thing that catches my eye is that you have no delimiters on your regex... that seems a little odd to me. is there a reason for it? now, to approach the actual regex issue: are you wanting to only grab the first name (the one within the single quotes)? if so, i think this should work:
$String = "Name: 'name' name name";
preg_match('|Name: [-0-9a-z\'_]{4,}|i', $String, $match);
echo $match[0];

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users