Re: [PHP] Regex help please

2009-03-27 Thread haliphax
On Fri, Mar 27, 2009 at 9:40 AM, Shawn McKenzie nos...@mckenzies.net wrote:
 I'm normally OK with regex, especially if I fiddle with it long enough,
 however I have fiddled with this one so long that I'm either totally
 missing it or it's something simple.  Does it have anything to do with
 the backref, or the fact that the value of the backref has a $?  I have:

 $out = '
 {$sites}
 tr
        td
        {Site.id}
        /td
 /tr
 {/$sites}';

 And I want to capture the first {$tag}, everything in between and the
 last {$/tag}.  I have tried several things and here is my current regex
 that looks like it should work, but doesn't:

 preg_match_all('|{\$([^}]+)}(.+)({/\1})|Us', $out, $matches);

Shawn,

First thing I see--your first capture group doesn't include the $, and
so your final capture group will always fail given your current $out
(because it's looking for {/sites} instead of {/$sites}). Also, your
{} are outside of your capture group in \1, but inside in \3. Here's
what I came up with:

$out = '
{$sites}
tr
   td
   {Site.id}
   /td
/tr
{/$sites}';
$matches = array();
preg_match_all('#{(\$[^}]+)}(.*?){(/\1)}#s', $out, $matches);
print_r($matches);

Produces this:

Array
(
[0] = Array
(
[0] = {$sites}
tr
   td
   {Site.id}
   /td
/tr
{/$sites}
)

[1] = Array
(
[0] = $sites
)

[2] = Array
(
[0] =
tr
   td
   {Site.id}
   /td
/tr

)

[3] = Array
(
[0] = /$sites
)

)

Keep in mind, I had to view the page source in order to see the HTML
tags, but it showed me everything I expected to see.

HTH,

-- 
// Todd

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help please

2009-03-27 Thread Shawn McKenzie
haliphax wrote:
 On Fri, Mar 27, 2009 at 9:40 AM, Shawn McKenzie nos...@mckenzies.net wrote:
 I'm normally OK with regex, especially if I fiddle with it long enough,
 however I have fiddled with this one so long that I'm either totally
 missing it or it's something simple.  Does it have anything to do with
 the backref, or the fact that the value of the backref has a $?  I have:

 $out = '
 {$sites}
 tr
td
{Site.id}
/td
 /tr
 {/$sites}';

 And I want to capture the first {$tag}, everything in between and the
 last {$/tag}.  I have tried several things and here is my current regex
 that looks like it should work, but doesn't:

 preg_match_all('|{\$([^}]+)}(.+)({/\1})|Us', $out, $matches);
 
 Shawn,
 
 First thing I see--your first capture group doesn't include the $, and
 so your final capture group will always fail given your current $out
 (because it's looking for {/sites} instead of {/$sites}). Also, your
 {} are outside of your capture group in \1, but inside in \3. Here's
 what I came up with:
 
 $out = '
 {$sites}
 tr
td
{Site.id}
/td
 /tr
 {/$sites}';
 $matches = array();
 preg_match_all('#{(\$[^}]+)}(.*?){(/\1)}#s', $out, $matches);
 print_r($matches);
 
 Produces this:
 
 Array
 (
 [0] = Array
 (
 [0] = {$sites}
 tr
td
{Site.id}
/td
 /tr
 {/$sites}
 )
 
 [1] = Array
 (
 [0] = $sites
 )
 
 [2] = Array
 (
 [0] =
 tr
td
{Site.id}
/td
 /tr
 
 )
 
 [3] = Array
 (
 [0] = /$sites
 )
 
 )
 
 Keep in mind, I had to view the page source in order to see the HTML
 tags, but it showed me everything I expected to see.
 
 HTH,
 

Yes, thank you.  I was fiddling before I got your post and I came up
with roughly the same.

preg_match_all('|{(\$[^}]+)}(.+){(/\1)}|Us', $out, $matches);

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regex help

2008-09-09 Thread Boyd, Todd M.
 -Original Message-
 From: Jason Pruim [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, September 09, 2008 7:30 AM
 To: PHP-General List
 Subject: [PHP] Regex help
 
 Hey everyone,
 
 Not completely specific to php but I know you guys know regex's
 better then I do! :)
 
 I am attempting to match purl.schreurprinting.com/jasonpruim112 to
 purl.schreurprinting.com/p.php?purl=jasonpruim112
 
 Here are my current matching patterns:
 
  RewriteRule /(.*) /volumes/raider/webserver/
 documents/dev/schreurprinting.com/p.php?purl=$
 #   RewriteRule /(*.) /purl.schreurprinting.com/$1
 #   RewriteRule /(mail.php?purl=*) /
 purl.schreurprinting.com/mail.php?purl=$1
 
 Yes I am doing this for apache's mod_rewrite, but my question is much
 more specific to regex's at this point :)
 
 Any ideas where I am going wrong? it seems like it should be fairly
 simple to do, but I don't know regex's at all :)

http://www.regular-expressions.info ... that's how I learned. :)
Anyway... your match might be something like:

^/([^/\.]+)/?$

And the rewrite...

/p.php?purl=$1

To break it down, the match is looking for The beginning of the line,
followed by a forward slash, followed by (begin capture group) 1 or more
characters that are not a forward slash or a period (end capture group)
followed by an optional forward slash, followed by the end of the line.

The rewrite is fairly straightforward.

I went 100% generic with the match due to your following e-mail that
stated jasonpruim112 could be any username. If 112 is necessary for
the match, it would be more like:

^/([^/\.]+112)/?$

Hope this helps,


Todd Boyd
Web Programmer




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex Help for URL's [ANSWER]

2006-05-17 Thread Edward Vermillion


On May 16, 2006, at 7:53 PM, Chrome wrote:


-Original Message-
From: Robert Samuel White [mailto:[EMAIL PROTECTED]
Sent: 17 May 2006 01:42
To: php-general@lists.php.net
Subject: RE: [PHP] Regex Help for URL's [ANSWER]



That's what I was doing.  I was parsing A:HREF, IMG:SRC, etc.

But when I implemented a new feature on my network, where you  
could click

on
a row and have it take you to another domain, I need a better  
solution.


Go to http://www.enetwizard.ws and it might make more sense.

All the links on the left have an ONCLICK=location.href = ''  
attribute in

the TR tag.

This solution allowed me to make sure those links included the  
session

information, just like the A:HREF links do.

It also had the advantage of updating the links in my CSS.


O that breaks accessibility standards! Compliment the  
'onclick's with

onkeydown at least :)

But still you get a solid onclick=... scenario

If these are visible in the source then they are fairly easy to  
pick out


Though you may need more than 1 regex ;)

My complaint here is, don't break accessibility :)



And don't forget the folks who have javascript turned off or are  
using text based browsers too.


Ed

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex Help for URL's

2006-05-17 Thread Kevin Waterson
This one time, at band camp, Robert Samuel White [EMAIL PROTECTED] wrote:

 Don't be rude.  I've already don't all of that.  Nothing came up.  I've been
 programming for 20 years (since I was 11 years old) so I'm not a slacker
 when it comes to learning new things, however, I have always found regular
 expressions to be extremely difficult.  Someone here might have the answer I
 need, and if so, I'd appreciate a response.  If you don't know the answer,
 don't reply.  Simple enough, don't you think?

Sorry, I missed most of this...
From what I gather you wish to extract urls from text?
if so..
function getLinks($string){
  // regex to get the links
  preg_match_all(|http:?([^\' ]+)|i, $string, $arrayoflinks);
  return $arrayoflinks;
}

Also check out this on line tutorial for regex geared towards PHP
http://phpro.org/tutorials/Introduction-to-PHP-Regular-Expressions.html

Kind regards
Kevin

-- 
Democracy is two wolves and a lamb voting on what to have for lunch. 
Liberty is a well-armed lamb contesting the vote.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex Help for URL's

2006-05-16 Thread Jochem Maas

Robert Samuel White wrote:

Can someone help me modify the following code?

It was designed to search for all instances of [LEVEL#]...[/LEVEL#]

I need a preg_match_all that will search for all of instances of an URL.

It should be sophisticated enough to find something as complicated as this:

http(s)://x.y.z.domain.com/dir/dir/file.name.ext?query=1query=2#anchor

Any help would be greatly appreciated!


so your looking for a regular expression that is *totally* different
from the regular expression you have... the two have nothing in common.

do you expect us to do the complete rewrite for you or do you want to
learn abit about regexps yourself? (that probably sounds arrogant, so it might
help to know even the most experienced people (a group I don't consider myself
part of) here have [and do] get told to RTFM on occasion - no one is safe ;-)

I suggest using a search engine to start with and see what that turns up...
somehow I can't believe that nobody has ever written a regexp that matches urls,
for instance try reading this page in the manual (hint: look at the the user 
notes)

http://php.net/preg_match

come back when/if you get stuck.



preg_match_all('#\[LEVEL([0-9])\](.*)\[/LEVEL[0-9]]#Uim', $arcContent,
$tmpMatches);

$arcContent = preg_replace('#\[LEVEL([0-9])\](.*)\[/LEVEL[0-9]]#Uim',
'###URL###', $arcContent); 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regex Help for URL's

2006-05-16 Thread Robert Samuel White
Don't be rude.  I've already don't all of that.  Nothing came up.  I've been
programming for 20 years (since I was 11 years old) so I'm not a slacker
when it comes to learning new things, however, I have always found regular
expressions to be extremely difficult.  Someone here might have the answer I
need, and if so, I'd appreciate a response.  If you don't know the answer,
don't reply.  Simple enough, don't you think?

-Original Message-
From: Jochem Maas [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, May 16, 2006 4:28 PM
To: Robert Samuel White
Cc: php-general@lists.php.net
Subject: Re: [PHP] Regex Help for URL's

Robert Samuel White wrote:
 Can someone help me modify the following code?
 
 It was designed to search for all instances of [LEVEL#]...[/LEVEL#]
 
 I need a preg_match_all that will search for all of instances of an URL.
 
 It should be sophisticated enough to find something as complicated as
this:
 
 http(s)://x.y.z.domain.com/dir/dir/file.name.ext?query=1query=2#anchor
 
 Any help would be greatly appreciated!

so your looking for a regular expression that is *totally* different
from the regular expression you have... the two have nothing in common.

do you expect us to do the complete rewrite for you or do you want to
learn abit about regexps yourself? (that probably sounds arrogant, so it
might
help to know even the most experienced people (a group I don't consider
myself
part of) here have [and do] get told to RTFM on occasion - no one is safe
;-)

I suggest using a search engine to start with and see what that turns up...
somehow I can't believe that nobody has ever written a regexp that matches
urls,
for instance try reading this page in the manual (hint: look at the the user
notes)

http://php.net/preg_match

come back when/if you get stuck.

 
 preg_match_all('#\[LEVEL([0-9])\](.*)\[/LEVEL[0-9]]#Uim', $arcContent,
 $tmpMatches);
 
 $arcContent = preg_replace('#\[LEVEL([0-9])\](.*)\[/LEVEL[0-9]]#Uim',
 '###URL###', $arcContent); 
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regex Help for URL's

2006-05-16 Thread Robert Cummings
On Tue, 2006-05-16 at 16:31, Robert Samuel White wrote:
 Don't be rude.  I've already don't all of that.  Nothing came up.  I've been
 programming for 20 years (since I was 11 years old) so I'm not a slacker
 when it comes to learning new things, however, I have always found regular
 expressions to be extremely difficult.  Someone here might have the answer I
 need, and if so, I'd appreciate a response.  If you don't know the answer,
 don't reply.  Simple enough, don't you think?

Perhaps a tad rude, but I got a treasure trove of hits from Google in my
first shot:

   
http://www.google.ca/search?hl=enq=regex+extract+urls+from+contentbtnG=Google+Searchmeta=

Formulating a good search query is a great skill to hone.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex Help for URL's

2006-05-16 Thread John Nichel

Robert Samuel White wrote:

Don't be rude.  I've already don't all of that.  Nothing came up.  I've been
programming for 20 years (since I was 11 years old) so I'm not a slacker
when it comes to learning new things, however, I have always found regular
expressions to be extremely difficult.  Someone here might have the answer I
need, and if so, I'd appreciate a response.  If you don't know the answer,
don't reply.  Simple enough, don't you think?


What's simple is a Google search.

If you don't want to do the leg work, don't ask us to do it for.  Simple 
enough, don't you think.


Because it makes the email hard to read.
Why is top posting bad?


-Original Message-
From: Jochem Maas [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, May 16, 2006 4:28 PM

To: Robert Samuel White
Cc: php-general@lists.php.net
Subject: Re: [PHP] Regex Help for URL's

Robert Samuel White wrote:

Can someone help me modify the following code?

It was designed to search for all instances of [LEVEL#]...[/LEVEL#]

I need a preg_match_all that will search for all of instances of an URL.

It should be sophisticated enough to find something as complicated as

this:

http(s)://x.y.z.domain.com/dir/dir/file.name.ext?query=1query=2#anchor

Any help would be greatly appreciated!


so your looking for a regular expression that is *totally* different
from the regular expression you have... the two have nothing in common.

do you expect us to do the complete rewrite for you or do you want to
learn abit about regexps yourself? (that probably sounds arrogant, so it
might
help to know even the most experienced people (a group I don't consider
myself
part of) here have [and do] get told to RTFM on occasion - no one is safe
;-)

I suggest using a search engine to start with and see what that turns up...
somehow I can't believe that nobody has ever written a regexp that matches
urls,
for instance try reading this page in the manual (hint: look at the the user
notes)

http://php.net/preg_match

come back when/if you get stuck.


preg_match_all('#\[LEVEL([0-9])\](.*)\[/LEVEL[0-9]]#Uim', $arcContent,
$tmpMatches);

$arcContent = preg_replace('#\[LEVEL([0-9])\](.*)\[/LEVEL[0-9]]#Uim',
'###URL###', $arcContent); 






--
John C. Nichel IV
Programmer/System Admin (ÜberGeek)
Dot Com Holdings of Buffalo
716.856.9675
[EMAIL PROTECTED]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regex Help for URL's

2006-05-16 Thread Robert Samuel White
I am trying to get all of the urls in a web document, so that I can append
information to the urls when needed (when the url points to a domain that
resides on my server).  It allows me to pass session information across the
domains of my network.  Currently, I use a class I wrote to handle this, but
it only works when it finds the urls in a standard html tag.  I need to
expand upon this, so that it also finds urls that are in onclick events, for
example.  Here is a sample page from my website:


SCRIPT LANGUAGE=JavaScriptif (parent != self) top.location.href =
location.href;/SCRIPTTABLE WIDTH=1000 BORDER=0 CELLPADDING=0
CELLSPACING=0 ALIGN=CENTER CLASS=TEMPLATE-TABLETRTD COLSPAN=7
CLASS=TEMPLATE-TABLE-TOP
TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100% HEIGHT=48
TR
TD WIDTH=60 ROWSPAN=2 ALIGN=RIGHTIMG
SRC=http://www.enetwizard.info/shared/enetwizard.gif; WIDTH=46
HEIGHT=46 BORDER=0 ALT= //TD
TD HEIGHT=24 VALIGN=BOTTOMDIV STYLE=font-family: sans-serif;
font-size: 8pt; font-weight: bold; color: white; margin-left:
10px;eNetwizard, Inc./DIV/TD
TD HEIGHT=24 VALIGN=BOTTOM ALIGN=RIGHTDIV STYLE=font-family:
sans-serif; font-size: 8pt; color: #FF; font-weight: bold; margin-right:
20px;
Anonymous Visitornbsp;nbsp;|nbsp;nbsp;A
HREF=http://www.enetwizard.cc/security.wizard?asset=welcomeamp;process=log
inamp;form=login STYLE=font-family: sans-serif; font-size: 8pt; color:
#6BDB17; font-weight: bold; text-decoration: underline;Log
In/Anbsp;nbsp;|nbsp;nbsp;A
HREF=http://www.enetwizard.cc/security.wizard?asset=welcomeamp;process=sig
nupamp;form=signup STYLE=font-family: sans-serif; font-size: 8pt; color:
#6BDB17; font-weight: bold; text-decoration: underline;Sign Up/A
/DIV/TD

/TRTR
TD HEIGHT=24 VALIGN=TOPDIV STYLE=font-family: sans-serif; font-size:
8pt; color: white; margin-left: 10px;IEmpowering Your
Creativity./I/DIV/TD
TD HEIGHT=24 VALIGN=TOP ALIGN=RIGHTDIV STYLE=font-family:
sans-serif; font-size: 8pt; color: #FF; margin-right: 20px;
ITuesday, May 16, 2006/I
/DIV/TD
/TR
/TABLE
/TD/TRTRTD COLSPAN=7 STYLE=height: 20px;DIV STYLE=font-size:
1px;nbsp;/DIV/TD/TRTRTD VALIGN=TOP STYLE=width: 20px;DIV
STYLE=font-size: 1px;nbsp;/DIV/TDTD VALIGN=TOP
CLASS=TEMPLATE-TABLE-LEFT STYLE=width: 180px;TABLE
CLASS=RSW-TABLETR CLASS=RSW-TABLE-HEAD-TRTD
CLASS=RSW-TABLE-HEAD-TDDIV CLASS=RSW-DIV-HEAD-CENTERSPAN
CLASS=RSW-FONT-HEAD-TEXTeNetwizard, Inc./SPAN/DIV/TD/TRTR
CLASS=RSW-TABLE-ROW1-TRTD CLASS=RSW-TABLE-ROW1-TD
ONMOUSEOVER=this.className = 'RSW-TABLE-SEP1-TD'; window.status = 'Backend
Manager'; return true; ONMOUSEOUT=this.className = 'RSW-TABLE-ROW1-TD';
window.status = ''; return true; ONCLICK=location.href =
'http://www.enetwizard.be/default.rsw'; return true; STYLE=cursor:
pointer;DIV CLASS=RSW-DIV-ROW1-LEFTSPAN CLASS=RSW-FONT-ROW1-TEXTA
CLASS=RSW-FONT-ROW1-LINK HREF=http://www.enetwizard.be/default.rsw;
ONMOUSEOVER=window.status = 'Backend Manager'; return true;
ONMOUSEOUT=window.status = ''; return true;Backend
Manager/ABReNetwizard.be/SPAN/DIV/TD/TRTR
CLASS=RSW-TABLE-ROW2-TRTD CLASS=RSW-TABLE-ROW2-TD
ONMOUSEOVER=this.className = 'RSW-TABLE-SEP2-TD'; window.status = 'Business
Headquarters'; return true; ONMOUSEOUT=this.className =
'RSW-TABLE-ROW2-TD'; window.status = ''; return true;
ONCLICK=location.href = 'http://www.enetwizard.biz/default.rsw'; return
true; STYLE=cursor: pointer;DIV CLASS=RSW-DIV-ROW2-LEFTSPAN
CLASS=RSW-FONT-ROW2-TEXTA CLASS=RSW-FONT-ROW2-LINK
HREF=http://www.enetwizard.biz/default.rsw; ONMOUSEOVER=window.status =
'Business Headquarters'; return true; ONMOUSEOUT=window.status = '';
return true;Business
Headquarters/ABReNetwizard.biz/SPAN/DIV/TD/TRTR
CLASS=RSW-TABLE-SEP1-TRTD CLASS=RSW-TABLE-SEP1-TD
ONMOUSEOVER=this.className = 'RSW-TABLE-SEP1-TD'; window.status = 'Client
Control Center'; return true; ONMOUSEOUT=this.className =
'RSW-TABLE-SEP1-TD'; window.status = ''; return true;
ONCLICK=location.href = 'http://www.enetwizard.cc/default.rsw'; return
true; STYLE=cursor: pointer;DIV CLASS=RSW-DIV-SEP1-LEFTSPAN
CLASS=RSW-FONT-SEP1-TEXTA CLASS=RSW-FONT-SEP1-LINK
HREF=http://www.enetwizard.cc/default.rsw; ONMOUSEOVER=window.status =
'Client Control Center'; return true; ONMOUSEOUT=window.status = '';
return true;Client Control
Center/ABReNetwizard.cc/SPAN/DIV/TD/TRTR
CLASS=RSW-TABLE-ROW2-TRTD CLASS=RSW-TABLE-ROW2-TD
ONMOUSEOVER=this.className = 'RSW-TABLE-SEP2-TD'; window.status =
'Development Services'; return true; ONMOUSEOUT=this.className =
'RSW-TABLE-ROW2-TD'; window.status = ''; return true;
ONCLICK=location.href = 'http://www.enetwizard.de/default.rsw'; return
true; STYLE=cursor: pointer;DIV CLASS=RSW-DIV-ROW2-LEFTSPAN
CLASS=RSW-FONT-ROW2-TEXTA CLASS=RSW-FONT-ROW2-LINK
HREF=http://www.enetwizard.de/default.rsw; ONMOUSEOVER=window.status =
'Development Services'; return true; ONMOUSEOUT=window.status = ''; return
true;Development Services/ABReNetwizard.de/SPAN/DIV/TD/TRTR
CLASS=RSW-TABLE-ROW1-TRTD CLASS=RSW-TABLE-ROW1-TD
ONMOUSEOVER=this.className = 'RSW-TABLE-SEP1-TD'; window.status = 

Re: [PHP] Regex Help for URL's

2006-05-16 Thread Jochem Maas

Robert Samuel White wrote:

Don't be rude.  I've already don't all of that.  Nothing came up.  I've been
programming for 20 years (since I was 11 years old) so I'm not a slacker
when it comes to learning new things, however, I have always found regular
expressions to be extremely difficult.  Someone here might have the answer I
need, and if so, I'd appreciate a response.  If you don't know the answer,
don't reply.  Simple enough, don't you think?


I wasn't being rude. Although even If I was commanding me stop is rather
futile no? if I was being rude I would have said something like:

read http://php.net/preg_match and find the get_links() function
 posted by 'max99x [at] gmail [dot] com'  you f*** wit

now that would have been rude.

the argument that the length of time spent programming automatically
makes you 'not a slacker' is unbased. one does not equate the other.
personally I would assume anyone who had been programming for 20 yrs
would have a reasonable understanding of regexps.



-Original Message-
From: Jochem Maas [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, May 16, 2006 4:28 PM

To: Robert Samuel White
Cc: php-general@lists.php.net
Subject: Re: [PHP] Regex Help for URL's

Robert Samuel White wrote:


Can someone help me modify the following code?

It was designed to search for all instances of [LEVEL#]...[/LEVEL#]

I need a preg_match_all that will search for all of instances of an URL.

It should be sophisticated enough to find something as complicated as


this:


http(s)://x.y.z.domain.com/dir/dir/file.name.ext?query=1query=2#anchor

Any help would be greatly appreciated!



so your looking for a regular expression that is *totally* different
from the regular expression you have... the two have nothing in common.

do you expect us to do the complete rewrite for you or do you want to
learn abit about regexps yourself? (that probably sounds arrogant, so it
might
help to know even the most experienced people (a group I don't consider
myself
part of) here have [and do] get told to RTFM on occasion - no one is safe
;-)

I suggest using a search engine to start with and see what that turns up...
somehow I can't believe that nobody has ever written a regexp that matches
urls,
for instance try reading this page in the manual (hint: look at the the user
notes)

http://php.net/preg_match

come back when/if you get stuck.



preg_match_all('#\[LEVEL([0-9])\](.*)\[/LEVEL[0-9]]#Uim', $arcContent,
$tmpMatches);

$arcContent = preg_replace('#\[LEVEL([0-9])\](.*)\[/LEVEL[0-9]]#Uim',
'###URL###', $arcContent); 






--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regex Help for URL's

2006-05-16 Thread Chrome
 -Original Message-
 From: Robert Samuel White [mailto:[EMAIL PROTECTED]
 Sent: 16 May 2006 21:32
 To: php-general@lists.php.net
 Subject: RE: [PHP] Regex Help for URL's
 
 Don't be rude.  I've already don't all of that.  Nothing came up.  I've
 been
 programming for 20 years (since I was 11 years old) so I'm not a slacker
 when it comes to learning new things, however, I have always found regular
 expressions to be extremely difficult.  Someone here might have the answer
 I
 need, and if so, I'd appreciate a response.  If you don't know the answer,
 don't reply.  Simple enough, don't you think?
 -Original Message-
 From: Jochem Maas [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, May 16, 2006 4:28 PM
 To: Robert Samuel White
 Cc: php-general@lists.php.net
 Subject: Re: [PHP] Regex Help for URL's
 
 Robert Samuel White wrote:
  Can someone help me modify the following code?
 
  It was designed to search for all instances of [LEVEL#]...[/LEVEL#]
 
  I need a preg_match_all that will search for all of instances of an URL.
 
  It should be sophisticated enough to find something as complicated as
 this:
 
  http(s)://x.y.z.domain.com/dir/dir/file.name.ext?query=1query=2#anchor
 
  Any help would be greatly appreciated!
 
 so your looking for a regular expression that is *totally* different
 from the regular expression you have... the two have nothing in common.
 
 do you expect us to do the complete rewrite for you or do you want to
 learn abit about regexps yourself? (that probably sounds arrogant, so it
 might
 help to know even the most experienced people (a group I don't consider
 myself
 part of) here have [and do] get told to RTFM on occasion - no one is safe
 ;-)
 
 I suggest using a search engine to start with and see what that turns
 up...
 somehow I can't believe that nobody has ever written a regexp that matches
 urls,
 for instance try reading this page in the manual (hint: look at the the
 user
 notes)
 
   http://php.net/preg_match
 
 come back when/if you get stuck.
 
 
  preg_match_all('#\[LEVEL([0-9])\](.*)\[/LEVEL[0-9]]#Uim', $arcContent,
  $tmpMatches);
 
  $arcContent = preg_replace('#\[LEVEL([0-9])\](.*)\[/LEVEL[0-9]]#Uim',
  '###URL###', $arcContent);
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 __ NOD32 1.1541 (20060516) Information __
 
 This message was checked by NOD32 antivirus system.
 http://www.eset.com

Bearing in mind that none of the replies (particularly that of Jochem, one
of the posters that should be held in high regard) have been rude in any way
at all, I understand your plight with regex's

You might want to try the Regex Coach... It allows you to test your regex's
offline and can really help

http://www.weitz.de/regex-coach/

HTH

Dan

Personal note: Stop using Lookout... it sucks

-- 
http://chrome.me.uk

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regex Help for URL's [ANSWER]

2006-05-16 Thread Robert Samuel White
In case any one is looking for a solution to a similar problem as me, here
is the answer.  I used the code from my original post as my guiding light,
and with some experimentation, I figured it out.

To get any URL, regardless of where it is located, use this:

preg_match_all(#\'http://(.*)\'#U, $content, $matches);

This match anything similar to:

'http://www.domain.com/dir/dir/file.txt?query=blah'

This is useful, if for example, you have a tag like this one:

A HREF=javascript:void(0); ONCLICK=javascript:window.open =
'http://www.domain.com/dir/dir/file.txt?query=blah';

Now, for tags which are in quotes, rather than single quotes, just use:

preg_match_all(#\http://(.*)\#U, $content, $matches);


This is really only the first step.

In order to be useful, you need a way to process these urls according to
your own specific needs:

preg_match_all(#\'http://(.*)\'#U, $content, $matches);

$content = preg_replace(#\'http://(.*)\'#U, '###URL###', $content);

This will modify the $content variable to change all urls to ###URL###

You can then go through them one at a time to process them:

for ($count = 0; $count  count($matches[1]); $count++)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regex Help for URL's [ANSWER]

2006-05-16 Thread Robert Cummings
On Tue, 2006-05-16 at 18:49, Robert Samuel White wrote:
 In case any one is looking for a solution to a similar problem as me, here
 is the answer.  I used the code from my original post as my guiding light,
 and with some experimentation, I figured it out.
 
 To get any URL, regardless of where it is located, use this:
 
 preg_match_all(#\'http://(.*)\'#U, $content, $matches);
 
 This match anything similar to:
 
 'http://www.domain.com/dir/dir/file.txt?query=blah'
 
 This is useful, if for example, you have a tag like this one:
 
 A HREF=javascript:void(0); ONCLICK=javascript:window.open =
 'http://www.domain.com/dir/dir/file.txt?query=blah';
 
 Now, for tags which are in quotes, rather than single quotes, just use:
 
 preg_match_all(#\http://(.*)\#U, $content, $matches);

I'd roll those two into one expression:

preg_match_all(#(\|')http://(.*)(\|')#U, $content, $matches);

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regex Help for URL's [ANSWER]

2006-05-16 Thread Richard Lynch
On Tue, May 16, 2006 6:21 pm, Robert Cummings wrote:
 On Tue, 2006-05-16 at 18:49, Robert Samuel White wrote:
 In case any one is looking for a solution to a similar problem as
 me, here
 preg_match_all(#(\|')http://(.*)(\|')#U, $content, $matches);

And it's missing the original requirement of matching https URLs, so
maybe make it be ...https?://...

Plus, http could be IN CAPS, so change the U to iU

And, actually, SOME old-school HTML pages will have neither ' nor 
around the URL, and are (or were) valid:
href=page2.html
was considered valid for HTML for a long long long time
So toss in (\|')?
And then you may be finding URLs that are not actually linked but are
part of the visible content, so maybe you only want the ones that
have
a[^]href=
in front of them.

If I can toss off 3 problems without even trying...

So I still think Google or searching the archives (as I suggested
off-list) will be the quickest route to a CORRECT answer, but here we
are again in this same thread we've been in every month or so for the
better part of a decade...

PS the (\|') bit may move the URLs into $matches[2] instead of
$matches[1] or whatever.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regex Help for URL's [ANSWER]

2006-05-16 Thread Robert Samuel White
All pages used by my content management system must be in a valid format.

Old-school style pages are never created so the solution I have come up with
is perfect for my needs.

Thank you.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regex Help for URL's [ANSWER]

2006-05-16 Thread Chrome

 -Original Message-
 From: Robert Samuel White [mailto:[EMAIL PROTECTED]
 Sent: 17 May 2006 01:16
 To: php-general@lists.php.net
 Subject: RE: [PHP] Regex Help for URL's [ANSWER]
 
 All pages used by my content management system must be in a valid format.
 
 Old-school style pages are never created so the solution I have come up
 with
 is perfect for my needs.
 
 Thank you.

Doesn't that make it a proprietary solution? IMHO offering the regex may
create a false situation for people... So the answer may not be for everyone

Might be wrong :)

Dan

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex Help for URL's

2006-05-16 Thread Richard Lynch
On Tue, May 16, 2006 4:22 pm, Jochem Maas wrote:
 personally I would assume anyone who had been programming for 20 yrs
 would have a reasonable understanding of regexps.

Nope.

:-)

I got WAY past 20 year mark before I even began to pretend to
understand the minimal amount of regex I can do now.

Most things complicated enough to need regex are too complicated to do
with regex, if you know what I mean...

There's a very narrow band of problems where I'm comfy with regex,
really.

Anything simpler than that is just a substr or explode.

Anything more complicated, and I just don't want to try to maintain
the mess of not-quite-random characters needed to make a so-called
pattern and I'll find some other way to break the problem down into
sub-problems.

Those sub-problems might then be amenable to a reasonable regex, of
course, but I'm just not gonna tackle it in one big messy pattern.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regex Help for URL's [ANSWER]

2006-05-16 Thread Robert Samuel White
In my opinion, it is the most reasonable solution.  I have looked all over
the web for something else, but this works perfectly for me.  It's
impossible to tell where an url starts and ends if you don't have it in
quotes or single quotes.  If someone really needs to find all the urls in a
page, then they'll code their pages to make use of this limitation.

-Original Message-
From: Chrome [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, May 16, 2006 8:24 PM
To: 'Robert Samuel White'; php-general@lists.php.net
Subject: RE: [PHP] Regex Help for URL's [ANSWER]


 -Original Message-
 From: Robert Samuel White [mailto:[EMAIL PROTECTED]
 Sent: 17 May 2006 01:16
 To: php-general@lists.php.net
 Subject: RE: [PHP] Regex Help for URL's [ANSWER]
 
 All pages used by my content management system must be in a valid format.
 
 Old-school style pages are never created so the solution I have come up
 with
 is perfect for my needs.
 
 Thank you.

Doesn't that make it a proprietary solution? IMHO offering the regex may
create a false situation for people... So the answer may not be for everyone

Might be wrong :)

Dan

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regex Help for URL's [ANSWER]

2006-05-16 Thread Chrome
 -Original Message-
 From: Robert Samuel White [mailto:[EMAIL PROTECTED]
 Sent: 17 May 2006 01:28
 To: php-general@lists.php.net
 Subject: RE: [PHP] Regex Help for URL's [ANSWER]
 
 In my opinion, it is the most reasonable solution.  I have looked all over
 the web for something else, but this works perfectly for me.  It's
 impossible to tell where an url starts and ends if you don't have it in
 quotes or single quotes.  If someone really needs to find all the urls in
 a
 page, then they'll code their pages to make use of this limitation.
 
 -Original Message-
 From: Chrome [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, May 16, 2006 8:24 PM
 To: 'Robert Samuel White'; php-general@lists.php.net
 Subject: RE: [PHP] Regex Help for URL's [ANSWER]
 
 
  -Original Message-
  From: Robert Samuel White [mailto:[EMAIL PROTECTED]
  Sent: 17 May 2006 01:16
  To: php-general@lists.php.net
  Subject: RE: [PHP] Regex Help for URL's [ANSWER]
 
  All pages used by my content management system must be in a valid
 format.
 
  Old-school style pages are never created so the solution I have come up
  with
  is perfect for my needs.
 
  Thank you.
 
 Doesn't that make it a proprietary solution? IMHO offering the regex may
 create a false situation for people... So the answer may not be for
 everyone
 
 Might be wrong :)
 
 Dan
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 __ NOD32 1.1542 (20060516) Information __
 
 This message was checked by NOD32 antivirus system.
 http://www.eset.com

If we are talking clickable links, why not focus on the a construct
itself? Otherwise URLs are just part of the page's textual content... Very
difficult to parse that

Disseminating an a tag isn't brain-meltingly difficult with a regex if you
put your mind to it... With or without quotes, be they single, double or
non-existent


If I've misunderstood please chastise me :)

HTH

Dan

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regex Help for URL's [ANSWER]

2006-05-16 Thread Robert Samuel White

 If we are talking clickable links, why not focus on the a construct
 itself? Otherwise URLs are just part of the page's textual content... Very
 difficult to parse that

 Disseminating an a tag isn't brain-meltingly difficult with a regex if
 you put your mind to it... With or without quotes, be they single, double 
 or non-existent

If I've misunderstood please chastise me :)

HTH

Dan


Dan,

That's what I was doing.  I was parsing A:HREF, IMG:SRC, etc.

But when I implemented a new feature on my network, where you could click on
a row and have it take you to another domain, I need a better solution.

Go to http://www.enetwizard.ws and it might make more sense.

All the links on the left have an ONCLICK=location.href = '' attribute in
the TR tag.

This solution allowed me to make sure those links included the session
information, just like the A:HREF links do.

It also had the advantage of updating the links in my CSS.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regex Help for URL's [ANSWER]

2006-05-16 Thread Chrome
 -Original Message-
 From: Robert Samuel White [mailto:[EMAIL PROTECTED]
 Sent: 17 May 2006 01:42
 To: php-general@lists.php.net
 Subject: RE: [PHP] Regex Help for URL's [ANSWER]
 
 
  If we are talking clickable links, why not focus on the a construct
  itself? Otherwise URLs are just part of the page's textual content...
 Very
  difficult to parse that
 
  Disseminating an a tag isn't brain-meltingly difficult with a regex if
  you put your mind to it... With or without quotes, be they single,
 double
  or non-existent
 
 If I've misunderstood please chastise me :)
 
 HTH
 
 Dan
 
 
 Dan,
 
 That's what I was doing.  I was parsing A:HREF, IMG:SRC, etc.
 
 But when I implemented a new feature on my network, where you could click
 on
 a row and have it take you to another domain, I need a better solution.
 
 Go to http://www.enetwizard.ws and it might make more sense.
 
 All the links on the left have an ONCLICK=location.href = '' attribute in
 the TR tag.
 
 This solution allowed me to make sure those links included the session
 information, just like the A:HREF links do.
 
 It also had the advantage of updating the links in my CSS.

O that breaks accessibility standards! Compliment the 'onclick's with
onkeydown at least :)

But still you get a solid onclick=... scenario

If these are visible in the source then they are fairly easy to pick out

Though you may need more than 1 regex ;)

My complaint here is, don't break accessibility :)

Dan


-- 
http://chrome.me.uk

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help

2006-01-14 Thread Curt Zirzow
On Fri, Jan 13, 2006 at 08:25:57AM -0500, Mike Smith wrote:
 I'm trying to save myself some time by extracting certain variables
 from a string:
 
 102-90 E 42 X 42 X 70 3/8
 
 I've been testing with: http://www.quanetic.com/regex.php
 and have been somewhat successful. Using this pattern:
 /[0-9]{2,}( X| x|x )/

The biggest problem with trying to match a string with regex is you
have to know the definition of what the string can be, for example
can the data be:
  
   102-90 E 42  X 42 X 70 3/8
   102-90 E 42 X  42 X 70 3/8
   102-90 E 42X42X70 3/8
   102-90 E 42\tX\t  42 \t X\n 70\r\n 3/8

 
 I have:
 102-90 E [!MATCH!] [!MATCH!] 70 3/8

If you want to just match those two numbers then:

  /\s+(\d{1,2})\s+(X|x)\s+(\d{1,2})\s+(X|x)\s+/

 
 
 Ideally what I want to do is update the db table that holds these records.
 ID: 1
 Unit: 102-90 E 42 X 42 X 70 3/8
 Panel: 42
 Width: 42
 Height: 70 3/8

If this is the case, where does the 102-90 E come from? This sounds
more like a data normalization issue than anything.
 
Curt.
-- 
cat .signature: No such file or directory

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regex help

2006-01-13 Thread Albert
Mike Smith wrote:
 I'm trying to save myself some time by extracting certain variables
 from a string:

 102-90 E 42 X 42 X 70 3/8

If this string is always in this format 

xxx E panel X width X height

then you could try something like:

// Very much untested
$unit = '102-90 E 42 X 42 X 70 3/8';
$split1 = explode('E', $unit);
list($panel, $width, $height) = explode('X', $split1[1]);

Albert

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.371 / Virus Database: 267.14.17/228 - Release Date: 2006/01/12
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help

2006-01-13 Thread Eric Martel

This should do the trick:

/(\d+) ?X ?(\d+) ?X ?(\d+ [\d\/]+)/i

(at least it would in Perl)

Le 13 Janvier 2006 08:25, Mike Smith a écrit :
 I'm trying to save myself some time by extracting certain variables
 from a string:

 102-90 E 42 X 42 X 70 3/8

 I've been testing with: http://www.quanetic.com/regex.php
 and have been somewhat successful. Using this pattern:
 /[0-9]{2,}( X| x|x )/

 I have:
 102-90 E [!MATCH!] [!MATCH!] 70 3/8


 Ideally what I want to do is update the db table that holds these records.
 ID: 1
 Unit: 102-90 E 42 X 42 X 70 3/8
 Panel: 42
 Width: 42
 Height: 70 3/8

 $pattern1 = '/[0-9]{2,}( X| x|x )/';
 $units = array of units above
 foreach($units AS $unit){
 preg_match($pattern1,$unit[1],$match);
 print_r($match);
 echo Panel: .$match[0];
 }

 The $match array is empty.

 Actually looking at the data there are so many typos (imported from
 Excel) that I will probably have to update by hand, but out of
 curiosity now what would be a good regex for the info given?

 Thanks,
 Mike Smith

-- 
Eric Martel
Sainte-Foy (Québec)
Canada

Ce courriel est signé numériquement avec la clef suivante:
This e-mail is digitally signed with the following key:
   ED3F191C (key://pgp.mit.edu, http://key.ericmartel.net/)
Empreinte/fingerprint:
   023D EFB7 8957 CBC0 C4E7 243D F01E D8A8 ED3F 191C
Pour plus d'information: http://gpg.ericmartel.net/
For more info:
http://kmself.home.netcom.com/Rants/gpg-signed-mail.html

There are flaws in Windows so great that they would
threaten national security if the Windows source code
were to be disclosed.  --Microsoft VP Jim Allchin, under oath

The intrinsic parallelism and free idea exchange in open
source software has benefits that are not replicable with
our current licensing model. --Microsoft
Read more on http://opensource.org/halloween/

Read between lines: get Linux! It's free, open source,
more secure, more reliable and more performant than
Window$.
http://www.linuxiso.org/


pgpL8YrMZ420Z.pgp
Description: PGP signature


Re: [PHP] Regex help

2006-01-13 Thread Mike Smith
Eric, thanks for replying. I couldn't quite get that to work. Albert,
I'm currently working with what you suggested, though the unit names
are not that consistent:

$vals = preg_split(' ?X? ',$unit[1]);
echo strong.$unit[1]./strongbr /\n;
echo Panel: .$vals[0].br /Width: .$vals[1].br /Height:
.$vals[2].br /\n;

202-90B 48 X 48 X 69 1/4
Panel: 202-90B 48
Width: 48
Height: 69 1/4

Thanks

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help

2005-11-18 Thread Robert Cummings
On Fri, 2005-11-18 at 10:55, Chris Boget wrote:
 Why isn't this regular expression
 
 ^[A-Za-z0-9\.]+\s*[A-Za-z0-9\.]*$
 
 allowing for this value:
 
 'Co. Dublin' (w/o the single quotes)
 
 ?  It's failing the regular expression match...

Do you have that expression embedded in single or double quotes? Please
show us the actual context.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help

2005-11-18 Thread David Grant
Chris,

if (preg_match(/^[A-Za-z0-9\.]+\s*[A-Za-z0-9\.]*$/, Co. Dublin))
echo TRUE;
else
echo FALSE;

prints TRUE for me.

Cheers,

David Grant

Chris Boget wrote:
 Why isn't this regular expression
 
 ^[A-Za-z0-9\.]+\s*[A-Za-z0-9\.]*$
 
 allowing for this value:
 
 'Co. Dublin' (w/o the single quotes)
 
 ?  It's failing the regular expression match...
 
 thnx,
 Chris
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex Help

2005-09-28 Thread Philip Hallstrom

Hi, folks.   I'm having trouble with a simple regex.  I'm sure it's just
something small that I'm missing but nothing I'm trying is working.

In an HTML file I have comments like this:

!-- START PRINT --
various html crap here
!-- END PRINT --

Here's the regex I'm using:

/!-- START PRINT --(.*?)!-- END PRINT --/

And then the call to preg_match_all():

preg_match_all($printable_reg, $str, $out);

It's been quite a while since I've worked with regular expressions so
I'm not sure what the problem is.  The regex isn't throwing errors, it's
just not matching the content located between the start print and end
print comments.

Can anyone lend a hand or give some advice?


I'm thinking that perhaps you want to add the s modifier to your 
pattern...



From http://us2.php.net/manual/en/reference.pcre.pattern.modifiers.php


s (PCRE_DOTALL)

If this modifier is set, a dot metacharacter in the pattern matches 
all characters, including newlines. Without it, newlines are excluded. 
This modifier is equivalent to Perl's /s modifier. A negative class such 
as [^a] always matches a newline character, independent of the setting of 
this modifier.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regex Help

2005-09-28 Thread Murray @ PlanetThoughtful
 Hi, folks.   I'm having trouble with a simple regex.  I'm sure it's just
 something small that I'm missing but nothing I'm trying is working.
 
 In an HTML file I have comments like this:
 
 !-- START PRINT --
 various html crap here
 !-- END PRINT --
 
 Here's the regex I'm using:
 
 /!-- START PRINT --(.*?)!-- END PRINT --/
 
 And then the call to preg_match_all():
 
 preg_match_all($printable_reg, $str, $out);
 
 It's been quite a while since I've worked with regular expressions so
 I'm not sure what the problem is.  The regex isn't throwing errors, it's
 just not matching the content located between the start print and end
 print comments.
 
 Can anyone lend a hand or give some advice?

Hi Pablo,

At a (reasonable) guess, I'd say it's because you're not using the s
pattern modifier in your preg_match_all()? The s modifier forces your
regular expression to match new lines with the . metacharacter.

Try:

preg_match_all(/!-- START PRINT --(.*?)!-- END PRINT --/s, $str,
$out);

http://php.planetmirror.com/manual/en/reference.pcre.pattern.modifiers.php

Hope this helps.

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regex Help

2005-09-28 Thread Pablo Gosse
Greetings folks.  Thanks Murray and Philip for the quick responses.
Adding the /s modifier worked perfectly.

Cheers,
Pablo

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] REGEX Help Please

2005-09-19 Thread John Nichel

Shaun wrote:

Hi,

I am trying to implement a regular expression so that I have a number 
between 0.00 and 1.00. the following works except I can go up to 1.99


$regexp = /^[0-1]{1}.[0-9]{2}/;

Can anyone help here please?

Thanks 



May have to go outside just a regex...

if ( preg_match ( /^\d{1}\.\d{2}$/, $number )  $number = 0  
$number = 1 )


--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
[EMAIL PROTECTED]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] REGEX Help Please

2005-09-19 Thread Robert Cummings
On Mon, 2005-09-19 at 10:11, John Nichel wrote:
 Shaun wrote:
  Hi,
  
  I am trying to implement a regular expression so that I have a number 
  between 0.00 and 1.00. the following works except I can go up to 1.99
  
  $regexp = /^[0-1]{1}.[0-9]{2}/;
  
  Can anyone help here please?
  
  Thanks 
  
 
 May have to go outside just a regex...
 
 if ( preg_match ( /^\d{1}\.\d{2}$/, $number )  $number = 0  
 $number = 1 )


$regexp = '/^((1\.00)|(0\.\d\d))$/';

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] REGEX Help Please

2005-09-19 Thread Stephen Leaf
On Monday 19 September 2005 09:03 am, Shaun wrote:
 Hi,

 I am trying to implement a regular expression so that I have a number
 between 0.00 and 1.00. the following works except I can go up to 1.99

 $regexp = /^[0-1]{1}.[0-9]{2}/;

 Can anyone help here please?

 Thanks

$regexp = /^(0\.[0-9]{2}|1\.00)/;

that should work :)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help

2005-08-07 Thread Dotan Cohen
On 8/4/05, Lizet Pena de Sola [EMAIL PROTECTED] wrote:
 Ok, it's not the regexp for detecting email addresses what I need,
 that's widely published, thanks. I'm using ereg to match this regular
 expression:
 
 (On)[\s\w\d\W\S\D\n]*(wr[i|o]te[s]?:)
 
 That will match phrases like
 On 8/3/05, Carol Swinehart [EMAIL PROTECTED] wrote:
 the type On date, name email wrote or writes:
 
 The thing is I tried this regexp with Regex Coach and it matches fine,
 but ereg returns no match
 
 ereg($regexpstr, $str, $regs)
 
 I know there are some comments at php.net about how ereg has some bugs,
 any idea if this could be one?
 
 Tia,
 Lizet

You're not going to get far with that. Lots of people make 'funny' You
Wrote lines, and not all of them start with 'On' or contain the word
'wr[o|i]te'. You might be better off just searching for any sentance
that contains an @ sign, because they are very seldom used outside of
email addresses nowadays. And that doesn't make any promises, either,
because sometimes the whole email address isn't in the line, just the
person's name.

Dotan Cohen
http://lyricslist.com/lyrics/artist_albums/286/judas_priest.php
Judas Priest Song Lyrics

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regex help

2005-08-04 Thread Lizet Pena de Sola
Ok, it's not the regexp for detecting email addresses what I need,
that's widely published, thanks. I'm using ereg to match this regular
expression:

(On)[\s\w\d\W\S\D\n]*(wr[i|o]te[s]?:)

That will match phrases like
On 8/3/05, Carol Swinehart [EMAIL PROTECTED] wrote:
the type On date, name email wrote or writes:

The thing is I tried this regexp with Regex Coach and it matches fine,
but ereg returns no match

ereg($regexpstr, $str, $regs)

I know there are some comments at php.net about how ereg has some bugs,
any idea if this could be one?

Tia, 
Lizet
-Original Message-
From: Marcus Bointon [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, August 03, 2005 8:57 AM
To: PHP General
Subject: Re: [PHP] Regex help

On 2 Aug 2005, at 15:12, Robin Vickery wrote:

 I don't suppose this is the place for a rant about the futility of
 checking email addresses with a regexp?

Though I will agree with you to some extent, I've had quite a lot of  
success with this, which is pretty thorough:

^(?:[\w\!\#\$\%\\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\\'\*\+\- 
\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61} 
[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)| 
(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4] 
\d|25[0-5])\]))$

Which I got from here:

http://www.hexillion.com/samples/#Regex

Marcus
-- 
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help

2005-08-03 Thread Marcus Bointon

On 2 Aug 2005, at 15:12, Robin Vickery wrote:


I don't suppose this is the place for a rant about the futility of
checking email addresses with a regexp?


Though I will agree with you to some extent, I've had quite a lot of  
success with this, which is pretty thorough:


^(?:[\w\!\#\$\%\\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\\'\*\+\- 
\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61} 
[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)| 
(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4] 
\d|25[0-5])\]))$


Which I got from here:

http://www.hexillion.com/samples/#Regex

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help

2005-08-02 Thread Robin Vickery
On 8/2/05, Chris Boget [EMAIL PROTECTED] wrote:
 I'm trying to validate an email address and for the life of me I
 cannot figure out why the following regex is not working:

   $email = [EMAIL PROTECTED];
   $regex =
 ^([a-zA-Z0-9_\.\-\']+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-\']+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$;

[a-zA-Z0-9\-\']

You don't escape hyphens like that in a character class. Put it at the
end of the list of characters like this:

[a-zA-Z0-9'-]

Then it'll match your test address. 

If you're trying to find out why a regexp isn't working, try
simplifying your test cases until it works. For example:

$email = [EMAIL PROTECTED]; // doesn't work
$email = [EMAIL PROTECTED];  // doesn't work
$email = [EMAIL PROTECTED];   // doesn't work
$email = [EMAIL PROTECTED];   // works!

I don't suppose this is the place for a rant about the futility of
checking email addresses with a regexp?

  -robin

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help

2005-08-02 Thread Dotan Cohen
On 8/2/05, Robin Vickery [EMAIL PROTECTED] wrote:
 I don't suppose this is the place for a rant about the futility of
 checking email addresses with a regexp?
 
   -robin

Let Richard Lynch tell him. He's good at regex's, and it's HIS email
address that never makes it through!

Dotan Cohen
http://lyricslist.com/lyrics/artist_albums/182/estefan_gloria.php
Estefan, Gloria Song Lyrics

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help

2005-06-06 Thread Philip Hallstrom

I am currently creating a once off text parser for a rather large
document that i need to strip out bits of information on certain
lines.

The line looks something like :


Adress line here, postcode, country Tel: +27 112233665 Fax: 221145221
Website: http://www.urlhere.com E-Mail: [EMAIL PROTECTED] TAGINCAPS: CAPS
RESPONSE Tag2: blah

I need to retreive the text after each marker i.e Tel: Fax: E-Email:
TAGINCAPS: ...

I have the following regex /Tel:\s*(.[^A-z:]+)/ and
/Fax:\s*(.[^A-z:]+)/ all these work as expected and stop just before
the next Tag. However I run into hassels  around the TAGINCAPS as the
response after it is all in caps and i cant get the Regex to stop just
before the next tag: which may be either all caps or lowercase.

I cant seem to find the regex that will retreive all chartures just
before a word with a :  regalrdless of case.

I have played around with the regex coach but still seem to be comming
up short so i thought i would see if anybody can see anything i might
have missed.


Any reason you can't match everything from TAGINCAPS through the end of 
the line, then once you have that stored in a string, split it on :'s to 
extract the pieces you want?  Even elements would be the tag, odd would be 
the value...


just a thought.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] RegEx help

2005-04-14 Thread Philip Hallstrom
On Thu, 14 Apr 2005, Bosky, Dave wrote:
I wanted to create a regex that force a PHP form text field to meet the
following requirements:
a. Must contain an 1 uppercase letter. [A-Z]
b. Must contain 1 digit. [0-9]
c. Must be a minimum of 7 characters in length. {7}
if ( ereg([A-Z0-9], $field)  strlen($field) = 7 ) {
print(We have a winner!);
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] RegEx help

2005-04-14 Thread M. Sokolewicz
Philip Hallstrom wrote:
On Thu, 14 Apr 2005, Bosky, Dave wrote:
I wanted to create a regex that force a PHP form text field to meet the
following requirements:
a. Must contain an 1 uppercase letter. [A-Z]
b. Must contain 1 digit. [0-9]
c. Must be a minimum of 7 characters in length. {7}
if ( ereg([A-Z0-9], $field)  strlen($field) = 7 ) {
print(We have a winner!);
}
nope, a username like 1234567 would go trough ok. Which isn't what he 
wanted

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] RegEx help

2005-04-14 Thread Tom Rogers
Hi,

Thursday, April 14, 2005, 11:47:13 PM, you wrote:
BD I wanted to create a regex that force a PHP form text field to meet the
BD following requirements:

BD a. Must contain an 1 uppercase letter. [A-Z]

BD b. Must contain 1 digit. [0-9]

BD c. Must be a minimum of 7 characters in length. {7}

 

BD I'm not sure of how to build the correct syntax for using all 3
BD requirements together.

BD Any help?

 

BD Thanks,

BD Dave

 

 



BD HTC Disclaimer:  The information contained in this message
BD may be privileged and confidential and protected from disclosure.
BD If the reader of this message is not the intended recipient, or an
BD employee or agent responsible for delivering this message to the
BD intended recipient, you are hereby notified that any
BD dissemination, distribution or copying of this communication is
BD strictly prohibited.  If you have received this communication in
BD error, please notify us immediately by replying to the message and
BD deleting it from your computer.  Thank you.

easier done seperately I think
if(
  strlen($text)  6 
  preg_match('/\d+/',$text) 
  preg_match('/[A-Z]+/',$text)
) { echo 'OK br';

-- 
regards,
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] RegEx help

2005-04-14 Thread Philip Hallstrom
I wanted to create a regex that force a PHP form text field to meet the
following requirements:
a. Must contain an 1 uppercase letter. [A-Z]
b. Must contain 1 digit. [0-9]
c. Must be a minimum of 7 characters in length. {7}
if ( ereg([A-Z0-9], $field)  strlen($field) = 7 ) {
print(We have a winner!);
}
nope, a username like 1234567 would go trough ok. Which isn't what he 
wanted
that's what I get for thinking too fast :)
Seems like you should be able to do then um... ([A-Z]|[0-9]) as your 
regexp (check on escaping the ()'s or not.  I can never remember)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] RegEx help

2005-04-14 Thread trlists
On 15 Apr 2005 Tom Rogers wrote:

 BD a. Must contain an 1 uppercase letter. [A-Z]
 BD b. Must contain 1 digit. [0-9]
 BD c. Must be a minimum of 7 characters in length. {7}
 
 BD I'm not sure of how to build the correct syntax for using all 3
 BD requirements together.

 easier done seperately I think
 if(
   strlen($text)  6 
   preg_match('/\d+/',$text) 
   preg_match('/[A-Z]+/',$text)
 ) { echo 'OK br';

To do it in one fell swoop you need to use lookahead assertions -- 
something like this:

if (preg_match('/(?=.*[A-Z])(?=.*[0-9]).{7,}/', $text))
echo 'Valid!';

I believe this matches for any string that has at least one uppercase 
letter and one digit and is at least 7 characters long.  However it 
allows other characters as well (not just A-Z and 0-9).  Lots of 
possible variations there.

--
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regex help

2005-01-29 Thread Michael Sims
[EMAIL PROTECTED] wrote:
 OK, this is off-topic like every other regex help post, but I know
 some of you enjoy these puzzles :)

This isn't an exam question, is it? ;)

 I need a validation regex that will pass a string. The string can
 be no longer than some maximum length, and it can contain any
 characters except two consecutive ampersands () anywhere in the
 string.

 I'm stumped - ideas?

Yup, use this perl regex:

/^(?:()(?!)|[^]){1,5}$/

Where 5 above is the maximum length of the string.  You can change this to
any positive value and the regex will still work.  Basically it says look
for 1 to 5 single characters where each either isn't an ampersand, or IS an
ampersand but isn't immediately followed by an ampersand.  The (?!) is a
zero-width negative look-ahead assertion which is like other assertions such
as \b that don't eat up the portions of the string that they match.

Sample code, tested:

$maxLen = 5;

$testStrings = array(
  'a',
  'g',
  'df',
  'adfdf',
  'adfsdfff',
  'ff',
  'dfds',
  'dsdf',
  'ddf',
  'dff'
);

foreach ($testStrings as $string) {
  if (preg_match(/^(?:()(?!)|[^]){1,$maxLen}$/, $string)) {
print $string matches.\n;
  } else {
print $string does not match.\n;
  }
}

Hope this helps you (pass your exam? ;) )

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regex help

2005-01-29 Thread Bret Hughes
On Sat, 2005-01-29 at 08:58, Michael Sims wrote:
 [EMAIL PROTECTED] wrote:
  OK, this is off-topic like every other regex help post, but I know
  some of you enjoy these puzzles :)
 
 This isn't an exam question, is it? ;)
 
  I need a validation regex that will pass a string. The string can
  be no longer than some maximum length, and it can contain any
  characters except two consecutive ampersands () anywhere in the
  string.
 
  I'm stumped - ideas?
 
 Yup, use this perl regex:
 
 /^(?:()(?!)|[^]){1,5}$/
 
 Where 5 above is the maximum length of the string.  You can change this to
 any positive value and the regex will still work.  Basically it says look
 for 1 to 5 single characters where each either isn't an ampersand, or IS an
 ampersand but isn't immediately followed by an ampersand.  The (?!) is a
 zero-width negative look-ahead assertion which is like other assertions such
 as \b that don't eat up the portions of the string that they match.


Great explanation.  Thanks from one who has not had an exam for over ten
years.

Bret

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regex help

2005-01-29 Thread Michael Sims
Bret Hughes wrote:
 On Sat, 2005-01-29 at 08:58, Michael Sims wrote:
 [EMAIL PROTECTED] wrote:
 I need a validation regex that will pass a string. The string can
 be no longer than some maximum length, and it can contain any
 characters except two consecutive ampersands () anywhere in the
 string.

 I'm stumped - ideas?

 Yup, use this perl regex:

 /^(?:()(?!)|[^]){1,5}$/

 Great explanation.  Thanks from one who has not had an exam for over
 ten years.

Thanks...I actually just realized that the parentheses around the first
ampersand are unnecessary (that was a leftover from a previous attempt), so
this is simpler and will work just as well:

/^(?:(?!)|[^]){1,5}$/

Or if you don't care about capturing portions of the match and then throwing
them away:

/^((?!)|[^]){1,5}$/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help

2005-01-29 Thread kjohnson
Michael Sims wrote:

  I need a validation regex that will pass a string. The string can
  be no longer than some maximum length, and it can contain any
  characters except two consecutive ampersands () anywhere in the
  string.

Yup, use this perl regex:

  /^(?:()(?!)|[^]){1,5}$/

[snip]

Hope this helps you (pass your exam? ;) )


Thanks, Michael! I guess it is time for me to go review those zero-width 
negative look-ahead assertions - don't know how I missed them ;)

And no, not an exam - this is real life. My days as a frolicking schoolboy 
are quite some distance behind me ;)

Kirk

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help

2005-01-28 Thread trlists
On 28 Jan 2005 [EMAIL PROTECTED] wrote:

 I need a validation regex that will pass a string. The string can be no 
 longer than some maximum length, and it can contain any characters except 
 two consecutive ampersands () anywhere in the string.

This is an example of something that is easier to do (and probably 
faster) without using a regexp:

if ((strlen($str) = $maxlen)  (strstr($str, '') === FALSE))
str is valid
else
str is not valid

--
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help

2005-01-28 Thread kjohnson
[EMAIL PROTECTED] wrote on 01/28/2005 03:19:14 PM:

 On 28 Jan 2005 [EMAIL PROTECTED] wrote:
 
  I need a validation regex that will pass a string. The string can be 
no 
  longer than some maximum length, and it can contain any characters 
except 
  two consecutive ampersands () anywhere in the string.
 
 This is an example of something that is easier to do (and probably 
 faster) without using a regexp:
 
if ((strlen($str) = $maxlen)  (strstr($str, '') === FALSE))
   str is valid
else
   str is not valid
 
 --
 Tom

Thanks, Tom. I agree, but not an option at this time - other parts of the 
design require this to be a regex.

Kirk

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help

2005-01-28 Thread Richard Lynch
[EMAIL PROTECTED] wrote:
 OK, this is off-topic like every other regex help post, but I know some
 of you enjoy these puzzles :)

 I need a validation regex that will pass a string. The string can be no
 longer than some maximum length, and it can contain any characters except
 two consecutive ampersands () anywhere in the string.

$text = $_REQUEST['text'];
if (strlne($text)  42  !strstr($text, '')){
  //kosher
}
else{
  trigger_error(Invalid input, E_USER_ERROR);
}

Oh, wait, that's not Regex.  Oh well.  Too bad.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help

2005-01-28 Thread Richard Lynch
[EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote on 01/28/2005 03:19:14 PM:

 On 28 Jan 2005 [EMAIL PROTECTED] wrote:

  I need a validation regex that will pass a string. The string can be
 no
  longer than some maximum length, and it can contain any characters
 except
  two consecutive ampersands () anywhere in the string.

 This is an example of something that is easier to do (and probably
 faster) without using a regexp:

if ((strlen($str) = $maxlen)  (strstr($str, '') === FALSE))
   str is valid
else
   str is not valid

 --
 Tom

 Thanks, Tom. I agree, but not an option at this time - other parts of the
 design require this to be a regex.

Gr.

Okay, how about that regex callback thingie thing thing, and you can use a
function that pretty much does: (strlen($1)  42  !strstr($1, ''))

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help

2005-01-28 Thread trlists
On 28 Jan 2005 [EMAIL PROTECTED] wrote:

 Thanks, Tom. I agree, but not an option at this time - other parts of the 
 design require this to be a regex.

It is pretty easy to do with two regexps, one to check the length and 
another to see if there is a double .  Would that work?  I don't know 
off hand how to do it with a single regexp.

If the design requires that every possible condition be checked with a 
single regexp then I would say, no offense intended, that the design is 
faulty.  Regexps are good tools but are not universal for all possible 
conditions one might want to test.

--
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help

2005-01-28 Thread kjohnson
[EMAIL PROTECTED] wrote on 01/28/2005 04:13:38 PM:

 On 28 Jan 2005 [EMAIL PROTECTED] wrote:
 
  Thanks, Tom. I agree, but not an option at this time - other parts of 
the 
  design require this to be a regex.
 
 It is pretty easy to do with two regexps, one to check the length and 
 another to see if there is a double .  Would that work?  I don't know 
 off hand how to do it with a single regexp.
 
 If the design requires that every possible condition be checked with a 
 single regexp then I would say, no offense intended, that the design is 
 faulty.  Regexps are good tools but are not universal for all possible 
 conditions one might want to test.

Thanks Tom and Richard. 

No offense taken. The design isn't mine, I am plugging in to another 
system that expects a regex.

I think I may have to push back on this one :)

Kirk

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regex help

2005-01-15 Thread Jason Morehouse
Mike Ford wrote:
Just off the top of my head (and untested!), I'd try something like
  /b(\s+[^]*)?/
Cheers!
Mike
That pretty much seems to work the best.  Thanks all!
--
Jason Morehouse
Vendorama - Create your own online store
http://www.vendorama.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] regex help

2005-01-14 Thread Robin Vickery
On Thu, 13 Jan 2005 16:06:32 -0500, Jason Morehouse [EMAIL PROTECTED] wrote:
 Hello,
 
 I normally can take a bit of regex fun, but not this time.
 
 Simple enough, in theory... I need to match (count) all of the bold tags
 in a string, including ones with embedded styles (or whatever else can
 go in there).  b and b style=color:red.  My attempts keep matching
 br as well.

Put in a \b to match a wordbreak after the 'b'. Something like this maybe:

  /b\b[^]*/i
.
-robin

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] regex help

2005-01-14 Thread Ford, Mike
To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm



 -Original Message-
 From: Jason Morehouse
 Sent: 13/01/05 21:06
 
 I normally can take a bit of regex fun, but not this time.
 
 Simple enough, in theory... I need to match (count) all of the bold
 tags
 
 in a string, including ones with embedded styles (or whatever else can
 go in there).  b and b style=color:red.  My attempts keep
 matching br as well.

Just off the top of my head (and untested!), I'd try something like

  /b(\s+[^]*)?/

Cheers!

Mike

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] regex help

2005-01-14 Thread Robinson, Matthew
Do you have the example regex so far?

I'd suggest maybe b[^r] might just do what you want 

-Original Message-
From: Jason Morehouse [mailto:[EMAIL PROTECTED] 
Sent: 13 January 2005 21:07
To: php-general@lists.php.net
Subject: [PHP] regex help

Hello,

I normally can take a bit of regex fun, but not this time.

Simple enough, in theory... I need to match (count) all of the bold tags
in a string, including ones with embedded styles (or whatever else can
go in there).  b and b style=color:red.  My attempts keep matching
br as well.

Thanks!

--
Jason Morehouse
Vendorama - Create your own online store http://www.vendorama.com

--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php



This message has been checked for all known viruses by the 
CitC Virus Scanning Service powered by SkyLabs. For further information
visit
http://www.citc.it

___


This message has been checked for all known viruses by the 
CitC Virus Scanning Service powered by SkyLabs. For further information visit
http://www.citc.it

___

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regex help

2005-01-14 Thread Jason Wong
On Friday 14 January 2005 05:06, Jason Morehouse wrote:

 Simple enough, in theory... I need to match (count) all of the bold tags
 in a string, including ones with embedded styles (or whatever else can
 go in there).  b and b style=color:red.  My attempts keep matching
 br as well.

Quick-n-dirty:

  preg_match_all('/(b|b\s+.*)/iU', $doo, $match);

Feel free to extend to check for closing tags :)

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
New Year Resolution: Ignore top posted posts

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regex help

2005-01-14 Thread Richard Lynch
Jason Morehouse wrote:
 Simple enough, in theory... I need to match (count) all of the bold tags
 in a string, including ones with embedded styles (or whatever else can
 go in there).  b and b style=color:red.  My attempts keep matching
 br as well.

I think something not unlike:

'/b( .*|)/'

The point being that you either have JUST ''  OR you have a SPACE and
whatever and ''

I leave the capitalization and 'greedy' settings up to you.

The previous solution using 'b[^r]' will work only until the goofball
browser wars give us some other bX tag where X is a single character in
the alphabet.

There's a pretty cool Windows/Linux product a colleague swears by that's
called RegexCoach (?) which will not only let you try out
expressions/values and tell you which ones pass/fail, but you can
highlight sub-sections of the expression/values and see what it matches
piece by piece.

It's donationware -- try it out and donate the $20 (oooh, hurt me) if you
like it.

http://www.weitz.de/regex-coach/

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regex help

2005-01-14 Thread Bret Hughes
On Thu, 2005-01-13 at 15:06, Jason Morehouse wrote:
 Hello,
 
 I normally can take a bit of regex fun, but not this time.
 
 Simple enough, in theory... I need to match (count) all of the bold tags 
 in a string, including ones with embedded styles (or whatever else can 
 go in there).  b and b style=color:red.  My attempts keep matching 
 br as well.
 

interesting.  I usually try to specifically describe in english what I
am looking for.  in your case, I would say a string that begins with 
followed by zero or more spaces followed by a b or a B followed by zero
or more spaces followed by zero or more anything followed by 

/\s*[bB]\s*.*/ 

or perhaps it is enough to say match a  followed by 0 or more spaces
followed by a b or a B and not followed by a r or a R and followed by
zero or more anything followed by 

/\s*[bB][^rR].*/

These are untested but should be close and can be used in preg*
functions.  the greedy matching might grab too much stuff and I always
forget how to do that when I hit it.

try them, let us see the results and we can get there

Bret


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regex help

2005-01-13 Thread Jochem Maas
Jason Morehouse wrote:
Hello,
I normally can take a bit of regex fun, but not this time.
Simple enough, in theory... I need to match (count) all of the bold tags 
in a string, including ones with embedded styles (or whatever else can 
go in there).  b and b style=color:red.  My attempts keep matching 
br as well.
okay, you didn't show the regexp you currently have no worries - I 
happen to have struck the same problem about 9 months ago when I had to 
screenscrape product info from a static site for importation into a DB,
heres a list of regexps which will hopefully give you enough info to
do what you want (the fifth regexp is the one you should look at most 
closely):

// strip out top and bottom
$str = preg_replace('/[\/]?html/is','',$str);
// strip out body tags
$str = preg_replace('/[\/]?body[^]*/is','',$str);
// strip out head
$str = preg_replace('/head.*[\/]head/Uis','',$str);
// strip out non product images
$str = 
preg_replace('/img[^]*(nieuw|new|euro)\.gif[^]*\/?/Uis','',$str);
// strip out font, div, span, p, b
$str = preg_replace('/[\/]?(font|div|span|p|b[^r])[^]*/Uis','',$str);
// table, td, tr attributes
$str = preg_replace('/(table|td|tr)[^]*/Uis','$1',$str);
// strip out the first table and hr?
$str = preg_replace('/table.*hr/Uis','',$str, 1);
// strip table, td, tr
$str = preg_replace('/[\/]?(table|td|tr|h5)/Ui','',$str);
// strip out all new lines
$str = str_replace(\n, '', $str);
// strip out tabs
$str = preg_replace('/[\011]+/', ' ', $str);
// strip out extra white space
$str = preg_replace('/[  ]+/', ' ', $str);


Thanks!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] regex help

2004-08-01 Thread Jim Grill
Can you post a little sample of the data and your current code?

thanks.

Jim Grill
Web-1 Hosting
http://www.web-1hosting.net

- Original Message - 
From: Kathleen Ballard [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Sunday, August 01, 2004 8:27 AM
Subject: [PHP] regex help


 I am at the tailend of a project that involves moving
 legacy data from one dbms to another.  The client has
 added a new requirement to the data manipulation that
 is required. I need to remove all br / tags (there
 may be more that one) that appear within all h*
 tags.  
 
 I am not very familiar with building regular
 expressions, but I see this as a 2 part process. 
 First, to grab h* tags, and second, to strip the
 br's. 
 
 I can grab the beginning of the tag easily, but my
 expressions grab too much.
 
 Also, I am not sure how to remove the br's.
 
 Any help would be appreciated.  I have tried to find
 similar examples, but without any luck.  Also, php5 is
 not an option at this point.
 
 Kathleen
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regex help

2004-08-01 Thread Justin Patrin
On Sun, 1 Aug 2004 06:27:51 -0700 (PDT), Kathleen Ballard
[EMAIL PROTECTED] wrote:
 I am at the tailend of a project that involves moving
 legacy data from one dbms to another.  The client has
 added a new requirement to the data manipulation that
 is required. I need to remove all br / tags (there
 may be more that one) that appear within all h*
 tags.
 
 I am not very familiar with building regular
 expressions, but I see this as a 2 part process.
 First, to grab h* tags, and second, to strip the
 br's.
 
 I can grab the beginning of the tag easily, but my
 expressions grab too much.
 
 Also, I am not sure how to remove the br's.
 
 Any help would be appreciated.  I have tried to find
 similar examples, but without any luck.  Also, php5 is
 not an option at this point.
 

$text = preg_replace('!(h\d[^]*.*?)br/(.*?/h\d)!is', '\1\2', $text);

You may also have to do this several times as this will only get one
br per h tag.

$newText = $text;
do {
  $text = $newText;
  $newText = preg_replace('!(h\d[^]*.*?)br/(.*?/h\d)!is', '\1\2', $text);
} while($text != $newText);

 Kathleen
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

-- 
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder

paperCrane --Justin Patrin--

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regex help

2004-08-01 Thread Justin Patrin
Forget my first attempt, using the e modifier and another preg_replace
is much better.

$return = preg_replace('!h(\d)(.*?)/h\1!ie',
'preg_replace(!br[^]*!i, , $1)', $originalText);

On Sun, 1 Aug 2004 13:39:49 -0700, Justin Patrin [EMAIL PROTECTED] wrote:
 On Sun, 1 Aug 2004 06:27:51 -0700 (PDT), Kathleen Ballard
 [EMAIL PROTECTED] wrote:
  I am at the tailend of a project that involves moving
  legacy data from one dbms to another.  The client has
  added a new requirement to the data manipulation that
  is required. I need to remove all br / tags (there
  may be more that one) that appear within all h*
  tags.
 
  I am not very familiar with building regular
  expressions, but I see this as a 2 part process.
  First, to grab h* tags, and second, to strip the
  br's.
 
  I can grab the beginning of the tag easily, but my
  expressions grab too much.
 
  Also, I am not sure how to remove the br's.
 
  Any help would be appreciated.  I have tried to find
  similar examples, but without any luck.  Also, php5 is
  not an option at this point.
 
 
 $text = preg_replace('!(h\d[^]*.*?)br/(.*?/h\d)!is', '\1\2', $text);
 
 You may also have to do this several times as this will only get one
 br per h tag.
 
 $newText = $text;
 do {
   $text = $newText;
   $newText = preg_replace('!(h\d[^]*.*?)br/(.*?/h\d)!is', '\1\2', $text);
 } while($text != $newText);
 
 
 
  Kathleen
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 --
 DB_DataObject_FormBuilder - The database at your fingertips
 http://pear.php.net/package/DB_DataObject_FormBuilder
 
 paperCrane --Justin Patrin--
 


-- 
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder

paperCrane --Justin Patrin--

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regex help needed

2004-08-01 Thread Wudi
On Sun, 1 Aug 2004 10:38:06 -0700 (PDT)
Kathleen Ballard [EMAIL PROTECTED] wrote:

 Sorry,
 Here is the code I am using to match the h* tags:
 
 h([1-9]){1}.*/h([1-9]){1}
 
 I have removed all the NL and CR chars from the string
 I am matching to make things easier.  Also, I have run
 tidy on the code so the tags are all uniform.
 
 The above string seems to match the tag well now, but
 I still need to remove the br tags from the tag
 contents (.*).
 
 The strings I will be matching are html formatted
 text.  Sample h* tags with content are below:
 
 h4Ex-Secretary Mickey Mouse br /Loses Mass.
 Primary/h4
 
 h4Ex-Secretary Mickey Mouse br /Loses Mass.
 Primary br / Wins New Jersey/h4
 
 h4Ex-Secretary Reich Loses Mass. Primary/h4
 
 Again, any help is appreciated.
 Kathleen

Simple:

while (preg_match(/(h\d)(.*)(br \/)(.*)(\/h\d)/is, $str)) {
$str = preg_replace(/(h\d)(.*)(br \/)(.*)(\/h\d)/is,
$1$2$4$5, $str);
}
$str = preg_replace(/(h\d)(.*)(\/h\d)/is, $2, $str);


Recommended:

$str = preg_replace(/(h\d)([^]*)()(.*)(\/h\d)/eis, remove_br('$4'), $str);
function remove_br($str){
return preg_replace(/(br)([^]*)()/i, , $str);
}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex Help

2004-05-10 Thread Curt Zirzow
* Thus wrote hitek ([EMAIL PROTECTED]):
 Greetings list,
 
 I have been given a list of products, and I need some help building a 
 regular expression to split the category from the sub category.
 Example:
 CamerasDigital_CannonXLRshot -Original entry in list
 Cameras Digital Cannon XLRshot -Desired result.

One possiblity:

echo preg_replace('/([a-z])_?([A-Z])/', '$1 $2', 'CamerasDigital_CannonXLRshot');

explanation: 
  match a lower case character preceding an uppercase character,
  with an optional underscore between them. Replace that match with
  the  matched lowercase character, space and matched uppercase character.



Curt
-- 
I used to think I was indecisive, but now I'm not so sure.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex Help

2004-05-10 Thread hitek
Curt,
That's perfect. Works like a charm.
Thanks,
Keith
At 03:54 PM 5/10/2004, Curt Zirzow wrote:
* Thus wrote hitek ([EMAIL PROTECTED]):
 Greetings list,

 I have been given a list of products, and I need some help building a
 regular expression to split the category from the sub category.
 Example:
 CamerasDigital_CannonXLRshot -Original entry in list
 Cameras Digital Cannon XLRshot -Desired result.
One possiblity:

echo preg_replace('/([a-z])_?([A-Z])/', '$1 $2', 
'CamerasDigital_CannonXLRshot');

explanation:
  match a lower case character preceding an uppercase character,
  with an optional underscore between them. Replace that match with
  the  matched lowercase character, space and matched uppercase character.


Curt
--
I used to think I was indecisive, but now I'm not so sure.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Regex help - PLease

2004-03-17 Thread Michal Migurski
Sorry I to should have added this this is what im going with so far

preg_match(/\d100.*/);

This will match a digit, followed by '100', followed by anything.
Go with Rob's suggestion.

-
michal migurski- contact info and pgp key:
sf/cahttp://mike.teczno.com/contact.html

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help - PLease

2004-03-16 Thread Richard Davey
Hello Brent,

Tuesday, March 16, 2004, 12:39:27 PM, you wrote:

BC im in desperate need of help for a reg expression to ONLY allow 8
BC NUMBERS to start with 100 and may not have any other kind of
BC letters or characters. Only numbers

BC for example 
BC 10064893

It's not a reg exp, but it will work:

if (is_numeric($val) == FALSE || strlen($val)  8 || substr($val, 0,
3) !== 100)
{
// $val doesn't match
}

Conversely:

if (is_numeric($val) == TRUE  strlen($val) == 8  substr($val, 0,
3) == 100)
{
// $val does match
}

(Code not tested, but you get the idea I hope)

-- 
Best regards,
 Richard Davey
 http://www.phpcommunity.org/wiki/296.html

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help - PLease

2004-03-16 Thread Rob Ellis
On Tue, Mar 16, 2004 at 02:39:27PM +0200, Brent Clark wrote:
 Hi there
 
 im in desperate need of help for a reg expression to ONLY allow 8 NUMBERS to start 
 with 100 and may not have any other kind of 
 letters or  characters. Only numbers
 
 for example 
 10064893
 

if (preg_match('/^100\d{5}/', $test))
print ok\n;

- rob

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help - PLease

2004-03-16 Thread Pablo
On 03/16/2004 6:57 AM, Rob Ellis [EMAIL PROTECTED] wrote:

 On Tue, Mar 16, 2004 at 02:39:27PM +0200, Brent Clark wrote:
 Hi there
 
 im in desperate need of help for a reg expression to ONLY allow 8 NUMBERS to
 start with 100 and may not have any other kind of
 letters or  characters. Only numbers
 
 for example 
 10064893
 
 
 if (preg_match('/^100\d{5}/', $test))
 print ok\n;

Unless you want to allow something like '10064893A' to match, use:

preg_match('/^100\d{5}$/', $test)

Pablo

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regex help

2004-03-15 Thread Chris W. Parker
Ryan A mailto:[EMAIL PROTECTED]
on Monday, March 15, 2004 9:07 AM said:

 I know this is pretty easy to do but I am horrorable at working with
 regular expressions and was wondering if anybody might take a min to
 help please.

in that case you should get the regex coach (easy to find via google).
it's great!

 I will have a variable:   $the_extention
 which will have a value like:98797-234234--2c-something-2c
 
 How do I take out the part which will always start with  --2c and
 will always end with -2c

by using () around the part you want to grab.

?php

  $string = 98797-234234--2c-something-2c;

  $pattern = /\d{5}-\d{6}--2c-(.*)-2c/;

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

  print_r($matches);

?

 A good baby steps tutorial on regex too would be appreciated.

there's lots of those. google can help you find them. try regular
expression tutorial or some variant of that.


hth,
chris.

p.s. i think you want extension not extention. :)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help

2004-03-15 Thread Jason Wong
On Tuesday 16 March 2004 01:06, Ryan A wrote:

 I know this is pretty easy to do but I am horrorable at working with
 regular expressions and was wondering if anybody might take a min to help
 please.

 I will have a variable:   $the_extention
 which will have a value like:98797-234234--2c-something-2c

 How do I take out the part which will always start with  --2c and will
 always end with -2c

For something as simple and predictable as that using regex seems to be an 
overkill. The simple string functions ought to be adequate. explode() might 
be all you need.

 eg:
 Using the above variable I want to do something like
 $second_extention= use_regex_here($the_extention)

 (value of $second_extention becomes: 98797-234234)

 A good baby steps tutorial on regex too would be appreciated.

google

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
When I left you, I was but the pupil.  Now, I am the master.
- Darth Vader
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help

2004-03-15 Thread Michal Migurski
I will have a variable:  $the_extention which will have a value like:
98797-234234--2c-something-2c

How do I take out the part which will always start with --2c and will
always end with -2c

You could use preg_replaces, like so:
$result = preg_replace('/--2c.+-c/', '', $the_extention);
That matches anything between '--2c' and '-2c' and replaces it with ''.

You could also use preg_match, like so:
preg_match('/^(.+)--2c.+-c$/', $the_extention, $matches);
$matches[1] should contain the substring you need.


A good baby steps tutorial on regex too would be appreciated.

Chapter 7 of Learning Perl is an excellent tutorial and basic reference.
http://www.oreilly.com/catalog/lperl3/

As usual, the trusty PHP manual also has good information:
http://www.php.net/manual/en/pcre.pattern.syntax.php

-
michal migurski- contact info and pgp key:
sf/cahttp://mike.teczno.com/contact.html

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help

2004-03-15 Thread Eric Gorr
At 6:06 PM +0100 3/15/04, Ryan A wrote:
I know this is pretty easy to do but I am horrorable at working with regular
expressions and was wondering if anybody might take a min to help please.
I will have a variable:   $the_extention
which will have a value like:98797-234234--2c-something-2c
How do I take out the part which will always start with  --2c and will
always end with -2c
I'd be interested in the answer to this question as well.
Seems like it should be easy.
A good baby steps tutorial on regex too would be appreciated.
This is a good one:

http://www.regular-expressions.info/tutorial.html

This google search turned up many tutorials:

http://tinyurl.com/2r3rf

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Regex help

2004-03-15 Thread Ryan A
Hey,
Thanks guys.

I did search on google first for a tutorial, problem is with something as
widely used as regular expressions
there are LOTS of results...I felt it would be better to ask if anyone has a
favourite..
ie:
if you learnt it off the web and not via the manual.

The last time I had this problem was with cookies and sessions, I found the
links I got from the people
on this list much better than the examples in the manual...after learning
from the web I did go back to the
manual and understood thing much better.

Cheers,
-Ryan


On 3/15/2004 6:18:38 PM, Chris W. Parker ([EMAIL PROTECTED]) wrote:
 Ryan A mailto:[EMAIL PROTECTED]
 on Monday, March 15, 2004 9:07 AM said:

  I know this is pretty easy to do but I am horrorable at working with
  regular expressions and was wondering if anybody might take a min to
  help please.

 in that case you should get the regex coach (easy to find via google).
 it's great!

  I will have a variable:   $the_extention
  which will have a value like:98797-234234--2c-something-2c
 
  How do I take out the part which will always start with  --2c and
  will always end with -2c

 by using () around the part you want to grab.

 ?php

 $string = 98797-234234--2c-something-2c;

 $pattern = /\d{5}-\d{6}--2c-(.*)-2c/;

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

 print_r($matches);

 ?

  A good baby steps tutorial on regex too would be appreciated.

 there's
 lots of those. google can help you find them. try
 regular
 expression tutorial or some variant of that.


 hth,
 chris.

 p.s. i think you want extension not extention. :)

 --
 PHP General Mailing List (http://www.php.net/)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help

2004-03-15 Thread trlists
On 15 Mar 2004 Eric Gorr wrote:

 which will have a value like:98797-234234--2c-something-2c
 
 How do I take out the part which will always start with  --2c and will
 always end with -2c
 
 I'd be interested in the answer to this question as well.
 Seems like it should be easy.

It is easy.  I agree with whoever said string functions were a better 
solution, regexp is overkill unless there is more variaiton in the data 
than what was presented.  That said, here are some possibilities; all 
but the first assume that the -- is always there:

- If the lengths are constant just use substr to pull out the
first 11 characters. 

- Find the -- with strpos and then use that in a substr call to
take just the part to the left. 

- Use explode to separate the string at the -- or --2c. 

- For two numeric strings separated by a dash use a regexp
approach something like this: 

if (preg_match(/^(\d*-\d*)--2c/, $string, $matches))
$left_part = $matches[1];

--
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help (SOLVED)

2004-03-15 Thread Ryan A
Hey Guys,
Solved this, took your advise and avoided regex as its an overkill.

Case you're interested:

$th_var=98797-234234--2c-something-2c;
$piece = explode(--2, $th_var);
echo $piece[0];

(and if i want to use the second part... $piece[1] )

Thanks to everyone who gave me examples, links and suggested alternatives
like explode(),
but personally I thought explode too was a regex..:-(.

Cheers,
-Ryan A

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help (SOLVED)

2004-03-15 Thread Michal Migurski
Thanks to everyone who gave me examples, links and suggested alternatives
like explode(), but personally I thought explode too was a regex..:-(.

explode() is not, split() is.

-
michal migurski- contact info and pgp key:
sf/cahttp://mike.teczno.com/contact.html

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] RegEx -- help

2003-10-10 Thread Mohamed Lrhazi
Untested:


function fixhisnumber($str){

//remove all but numbers
$str = preg_replace(/[^0-9]/,,$str);

//append 1, unless it's already there
$str = $str[0] == '1'? $str:1.$str;

if (strlen($str) == 10) return $str;
else return -1;

}

Mohamed~

On Fri, 2003-10-10 at 14:01, Lists wrote:
 I do not know if this is the right list, but if someone could help me with 
 the following
 
 I need a function that does this:
 
 function phone($num) {
 
 take num and remove anything that is not a number
 ex: () - / 
 
 
 If there is not 1 at the start, add a one to the start of the number.
 
 make sure that the number is 10 digits (if not return -1)
 
 
 }
 
 Thank you for your help,
 
 Michael

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help appreciated

2003-08-14 Thread Mukul Sabharwal
Firstly,

If your text spans more than one line you should use
\n, rather than just doing something like :

a href=\
hello\...(.*)/a

because that will mess up, depending on what text
editor you use, eg. notepad will put \r\n, but it
should only be \n. Though I'm not sure about it.

So the best solution is :

a href=\\nhell\...(.*)/a

Now that said, let's look into your problem, you
mention you want one common regex that does both of
them. That would be tideous enough to let be, instead
using two distinct regex checks would be easier, and
faster.

So :

eregi('para font-size=12 font-family=Arial
style=heading 2(.*)anchor
type=bkmrk/(.*)/para', $string, $matches);

would store Some in $matches[1], more text- in
$matches[2].

eregi('para font-size=12 font-family=Arial
style=heading 2inline
caps=false(.*)/inline(.*)/para', $string,
$datex);

would store Some text in $datex[1], more text in
$datex[2]

Now if you want to know which one to execute, just do
a

if(eregi('inline caps=false', $input_string)) {

execute_this_Regex();

}

It should be faster this way, and an even more
efficient solution can be using Perl Regex.

HTH

Mukul Sabharwal
http://www.dehvome.org


- Original Message - 
From: David Pratt [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, August 12, 2003 10:55 AM
Subject: [PHP] Regex help appreciated


 I am trying to get a regex to extract the Some and
more text 
 between the para elements below in a single pass for
style attribute of 
 heading 2
 
 para font-size=12 font-family=Arial
style=heading 2Someanchor 
 type=bkmrk/more text-/para
 
 para font-size=12 font-family=Arial
style=heading 2inline 
 caps=falseSome text/inlinemore text/para
 
 Tried something like this for first bit but grabbing
the anchor tag 
 with the text.
 
 |para(.*)style=\heading
2\(([a-zA-Z0-9/-/_/\s]+)?)([anchor 
 type=bkmrk name=[a-zA-Z0-9/_]+/])?(.*)/para|
 
 Help much appreciated.
 Thanx
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

__
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regex help?

2003-07-21 Thread David Nicholson
Hello,

This is a reply to an e-mail that you wrote on Mon, 21 Jul 2003 at
08:59, lines prefixed by '' were originally written by you.
 Can't seem to get this to work...
 trying to yank stuff xxx from
 TD class=a8b noWrap align=middle width=17
bgColor=#ccxxx/td

Try this:

preg_match(/td[^]*(.*)/TD/i, $l, $regs);

HTH

David.

--
phpmachine :: The quick and easy to use service providing you with
professionally developed PHP scripts :: http://www.phpmachine.com/

  Professional Web Development by David Nicholson
http://www.djnicholson.com/

QuizSender.com - How well do your friends actually know you?
 http://www.quizsender.com/
(developed entirely in PHP)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex help needed

2003-07-16 Thread Curt Zirzow
Sid [EMAIL PROTECTED] wrote:
 Hello,
 
 Well I am doing by first reg ex operations and I am having problems which I just 
 cannot figure out.
 
 For example I tried
 echo eregi_replace (tr bgcolor=\#F8F8F1\(\s*)td\s*font 
 size=\2\\s*purchasing power parity, '%POWER%', 'tdtrsdsdsstr 
 bgcolor=#f8f8f1tdfont size=2Purchasing power parity');
 and this worked perfectly,
 
 but when I chnaged that to
 echo eregi_replace (tr bgcolor=\#F8F8F1\(\s*)td\s*font 
 size=\2\\s*purchasing\s+power\s+parity, '%POWER%', 'tdtrsdsdsstr 
 bgcolor=#f8f8f1tdfont size=2Purchasing power parity');
 It does not detect the string. Srange. According to what I know, \s+ will detect a 
 single space also. I tried chnaging the last 2 \s+ to \s* but this did not work also.
 Any ideas on this one?


I'd do something like this, unless your string must have to have the 
attributes to the html elements.

tr[^]*[[:space:]]*td[^]*[[:space:]]*font[^]*[[:space:]]*purchasing[[:space:]]*power[[:space:]]*parity

 As I proceed I would like the expression to detect the optional face attribute also, 
 so I tried
 echo eregi_replace (tr bgcolor=\#F8F8F1\(\s*)td\s*font 
 size=\2\(\s+face=\Verdana, Arial, Helvetica, sans-serif\|)\s*purchasing power 
 parity, '%POWER%', 'tdtrsdsdsstr bgcolor=#f8f8f1 face=Verdana, Arial, 
 Helvetica, sans-seriftdfont size=2Purchasing power parity');
 ... and this gave me an error like
 Warning: eregi_replace(): REG_EMPTY:çempty (sub)expression in D:\sid\dg\test.php on 
 line 2

(\s+face=\Verdana, Arial, Helvetica, sans-serif\|)\s*purchasing power parity
the problem is regex is expecting something here---^

you can change it to:
(\s+face=\Verdana, Arial, Helvetica, sans-serif\|)\s*purchasing power parity

 
 Any ideas? BTW any place where I can get started on regex? I got a perl book that 
 explains regex, but I have got to learn perl first (I dont know any perl)

Go right to the source:
http://www.oreilly.com/catalog/regex/

 
 Thanks in advance.
 
 - Sid

Curt
-- 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Regex Help

2003-02-11 Thread Ernest E Vogelsinger
At 07:47 11.02.2003, Lord Loh. said:
[snip]
I am new to regex and broke my head on it the other day...in vain...

Can any one tell me a place to get a step by step tutorial on it or help me
out on how to work it out ?

http://www.php.net/manual/en/ref.pcre.php
http://www.perldoc.com/perl5.6/pod/perlre.html


-- 
   O Ernest E. Vogelsinger
   (\)ICQ #13394035
^ http://www.vogelsinger.at/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Regex Help

2003-02-11 Thread Kevin Waterson
This one time, at band camp,
Lord Loh. [EMAIL PROTECTED] wrote:

 I am trying to make a link collector.
 
 after opening the desired page, I want to get all the hyperlinks on it...

OK, this is quick and nasty, but you can add sanity/error checking etc
as you please, but it shows you the concept..

?php

  // tell me its broken
  error_reporting(E_ALL);

class grabber{

  function grabber(){

}

function getLinks(){
  // regex to get the links
  $contents = $this-getUrl();
  preg_match_all(|http:?([^\' ]+)|i, $contents, $arrayoflinks);
  return $arrayoflinks;
}

// snarf the url into a string
function getUrl(){
  return file_get_contents($_POST['url']);
}


} // end class
?

html
body
h1Link Grabber/h1
form action=?php echo $_SERVER['PHP_SELF']; ? method=post
table
trtdURL:/tdtdinput type=text name=url maxlength=100 size=50 
value=http://www.php.net;/td/tr
trtdinput type=submit value=Grab em/td/tr
/table
/form

?php
  // check something was posted
  if(!isset($_POST['url']) || $_POST['url']=='')
{
// or tell them to
echo 'Please Enter a Valid url';
}
  else
{
// create a new grabber
$grab = new grabber;
// snarf the links
$arr=$grab-getLinks();
// check the size of the array
if(sizeof($arr['0'])=='0')
{
// echo out a little error
echo 'No links found in file '.$_POST['url'];
}
else
{
// filter out duplicates and print the results
foreach(array_unique($arr['0']) as $val){ echo 'a 
href='.$val.''.$val.'br /'; }
}
}
?
/body/html


enjoy,
Kevin
-- 
 __  
(_ \ 
 _) )            
|  /  / _  ) / _  | / ___) / _  )
| |  ( (/ / ( ( | |( (___ ( (/ / 
|_|   \) \_||_| \) \)
Kevin Waterson
Port Macquarie, Australia

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Regex Help

2002-12-19 Thread Rick Emery
addslashes()

- Original Message - 
From: Jim [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, December 19, 2002 11:26 AM
Subject: [PHP] Regex Help


Could someone show me how to use preg_replace to change this:

test OPTION VALUE=testtest/OPTION test

into:

anotherword OPTION VALUE=\test\test/OPTION anotherword

basically, I want to change a value only if it is not in an option
tag.

I also want to account for situations like :

test, something OPTION VALUE=testtest/OPTION test!

My thoughts were to do the replace if the word (test) was not
surrounded by quotes or surrounded by greater/less than symbols. I
just have no idea how to formulate that with regex.

Please help! Thanks.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Regex Help

2002-12-19 Thread Jim
I'm sorry, I accidentally left the slashes on my second example. My original
message should read:

Could someone show me how to use preg_replace to change this:

test OPTION VALUE=testtest/OPTION test

into:

anotherword OPTION VALUE=testtest/OPTION anotherword

Note that what I want to accomplish is to change 'test' into 'anotherword'
only if it is not within the option tag.

Thanks!


- Original Message -
From: Rick Emery [EMAIL PROTECTED]
To: Jim [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Thursday, December 19, 2002 12:42 PM
Subject: Re: [PHP] Regex Help


 addslashes()

 - Original Message -
 From: Jim [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Thursday, December 19, 2002 11:26 AM
 Subject: [PHP] Regex Help


 Could someone show me how to use preg_replace to change this:

 test OPTION VALUE=testtest/OPTION test

 into:

 anotherword OPTION VALUE=\test\test/OPTION anotherword

 basically, I want to change a value only if it is not in an option
 tag.

 I also want to account for situations like :

 test, something OPTION VALUE=testtest/OPTION test!

 My thoughts were to do the replace if the word (test) was not
 surrounded by quotes or surrounded by greater/less than symbols. I
 just have no idea how to formulate that with regex.

 Please help! Thanks.

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php






-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Regex Help

2002-12-19 Thread Rick Emery
?php
$q = test OPTION VALUE=\test\test/OPTION test;
ereg((.*)(OPTION.*OPTION)(.*),$q,$ar);
$t = anotherword.$ar[2].anotherword;
print $t;
?

outputs:
anotherwordOPTION VALUE=testtest/OPTIONanotherword

- Original Message - 
From: Jim [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, December 19, 2002 11:55 AM
Subject: Re: [PHP] Regex Help


I'm sorry, I accidentally left the slashes on my second example. My original
message should read:

Could someone show me how to use preg_replace to change this:

test OPTION VALUE=testtest/OPTION test

into:

anotherword OPTION VALUE=testtest/OPTION anotherword

Note that what I want to accomplish is to change 'test' into 'anotherword'
only if it is not within the option tag.

Thanks!


- Original Message -
From: Rick Emery [EMAIL PROTECTED]
To: Jim [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Thursday, December 19, 2002 12:42 PM
Subject: Re: [PHP] Regex Help


 addslashes()

 - Original Message -
 From: Jim [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Thursday, December 19, 2002 11:26 AM
 Subject: [PHP] Regex Help


 Could someone show me how to use preg_replace to change this:

 test OPTION VALUE=testtest/OPTION test

 into:

 anotherword OPTION VALUE=\test\test/OPTION anotherword

 basically, I want to change a value only if it is not in an option
 tag.

 I also want to account for situations like :

 test, something OPTION VALUE=testtest/OPTION test!

 My thoughts were to do the replace if the word (test) was not
 surrounded by quotes or surrounded by greater/less than symbols. I
 just have no idea how to formulate that with regex.

 Please help! Thanks.

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php






-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Regex Help

2002-12-19 Thread Jim
Thanks for helping. Unfortunately, that doesn't quite accomplish the task
either. The other example for my first post would be mangled with that.

- Original Message -
From: Rick Emery [EMAIL PROTECTED]
To: Jim [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Thursday, December 19, 2002 1:09 PM
Subject: Re: [PHP] Regex Help


 ?php
 $q = test OPTION VALUE=\test\test/OPTION test;
 ereg((.*)(OPTION.*OPTION)(.*),$q,$ar);
 $t = anotherword.$ar[2].anotherword;
 print $t;
 ?

 outputs:
 anotherwordOPTION VALUE=testtest/OPTIONanotherword



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Regex Help

2002-12-19 Thread Jim
Whoops, sorry post aborted prematurely.

What I was going say say was that:

test, something OPTION VALUE=testtest/OPTION test!

should become:

anotherword, something OPTION VALUE=testtest/OPTION anotherword!

Thanks again for helping!


- Original Message - 
From: Jim [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, December 19, 2002 1:24 PM
Subject: Re: [PHP] Regex Help


 Thanks for helping. Unfortunately, that doesn't quite accomplish the task
 either. The other example for my first post would be mangled with that.
 
 - Original Message -
 From: Rick Emery [EMAIL PROTECTED]
 To: Jim [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Sent: Thursday, December 19, 2002 1:09 PM
 Subject: Re: [PHP] Regex Help
 
 
  ?php
  $q = test OPTION VALUE=\test\test/OPTION test;
  ereg((.*)(OPTION.*OPTION)(.*),$q,$ar);
  $t = anotherword.$ar[2].anotherword;
  print $t;
  ?
 
  outputs:
  anotherwordOPTION VALUE=testtest/OPTIONanotherword
 
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Regex Help

2002-12-19 Thread Rick Emery
gawd, Jim, you are s oicky GRIN

?php
$q = test, something OPTION VALUE=\test\test/OPTION test;
ereg((.*)(OPTION.*OPTION)(.*),$q,$ar);
$w1 = ereg_replace(test,anotherword,$ar[1]);
$w2 = ereg_replace(test,anotherword,$ar[3]);
$t = $w1.$ar[2].$w2;
print $t;

?

outputs:
anotherword, something OPTION VALUE=testtest/OPTION anotherword

- Original Message - 
From: Jim [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, December 19, 2002 12:25 PM
Subject: Re: [PHP] Regex Help


Whoops, sorry post aborted prematurely.

What I was going say say was that:

test, something OPTION VALUE=testtest/OPTION test!

should become:

anotherword, something OPTION VALUE=testtest/OPTION anotherword!

Thanks again for helping!


- Original Message - 
From: Jim [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, December 19, 2002 1:24 PM
Subject: Re: [PHP] Regex Help


 Thanks for helping. Unfortunately, that doesn't quite accomplish the task
 either. The other example for my first post would be mangled with that.
 
 - Original Message -
 From: Rick Emery [EMAIL PROTECTED]
 To: Jim [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Sent: Thursday, December 19, 2002 1:09 PM
 Subject: Re: [PHP] Regex Help
 
 
  ?php
  $q = test OPTION VALUE=\test\test/OPTION test;
  ereg((.*)(OPTION.*OPTION)(.*),$q,$ar);
  $t = anotherword.$ar[2].anotherword;
  print $t;
  ?
 
  outputs:
  anotherwordOPTION VALUE=testtest/OPTIONanotherword
 
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Regex Help

2002-12-19 Thread John W. Holmes
There may be better ways, but this little example works. You basically
match everything around the option tag and run a replace on what's
outside of it, and then put it all back together. This example should
run as is. Adapt to your needs. 

?

header(Content-type: text/plain);

$word = test;
$repl = anotherword;

$new_string = ;
$string = 
This test is a test okay? option value='test'test/option and this
test is good
This test on line 2option value='whatever'thing/option
option value='foo'foo/option test on line 3
option value='foo2'foo2/option
Testoptiontest/optionTest;

preg_match_all(/(.*)(option.*option)(.*)/i,$string,$match);

$cnt = count($match[1]);

for($x=0;$x$cnt;$x++)
{
$p1 = preg_replace(/$word/i,$repl,$match[1][$x]);
$p2 = preg_replace(/$word/i,$repl,$match[3][$x]);

$new_string .= $p1 . $match[2][$x] . $p2 . \n;
}

echo $string\n--\n$new_string;

?

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/

 -Original Message-
 From: Jim [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, December 19, 2002 1:24 PM
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP] Regex Help
 
 Thanks for helping. Unfortunately, that doesn't quite accomplish the
task
 either. The other example for my first post would be mangled with
that.
 
 - Original Message -
 From: Rick Emery [EMAIL PROTECTED]
 To: Jim [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Sent: Thursday, December 19, 2002 1:09 PM
 Subject: Re: [PHP] Regex Help
 
 
  ?php
  $q = test OPTION VALUE=\test\test/OPTION test;
  ereg((.*)(OPTION.*OPTION)(.*),$q,$ar);
  $t = anotherword.$ar[2].anotherword;
  print $t;
  ?
 
  outputs:
  anotherwordOPTION VALUE=testtest/OPTIONanotherword
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Regex Help

2002-10-30 Thread Marek Kilimajer
Instead of splitting the string on chars that don't equal \w and ', 
split it on chars that equal \s (or any other you need)

Gerard Samuel wrote:

Im trying to explode a string into an array of words using -
$title = preg_split('/[^\w\']/', $title, -1,  PREG_SPLIT_NO_EMPTY );

It seems to work well with words like this and don't but it 
doens't work with words with accents to it like
Guantánamo
Could my regex be expanded to handle non-english type characters, or 
any workarounds to get a string into an array of words,
where the string contains non english characters??

Thanks



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] regex help

2002-05-26 Thread Miguel Cruz

I use this, but it's a preg rather than ereg pattern:

 '/([a-z0-9]+[a-z0-9\-]*\.)+[a-z0-9]+[a-z0-9\-]*[a-z0-9]+$/i'

Two problems (which in practice are so slight that I've foregone my usual 
standards-analness to ignore them) 

  1) It will allow a domain name component (except the final one) to end 
 with a dash (e.g., test-.example.com).

  2) It will not allow a one-character final component.

miguel

On Sun, 26 May 2002, Jeff Field wrote:
 This is not really specific to PHP (although the information might be useful
 for all that form validation we all do), and for that I apologize in advance
 (does anyone know of a regex mailing list?), but maybe someone here can help
 with the following:
 
 I find no good regex for checking valid domain names.  None that I have seen
 take into account the fact that, although dashes (-) and dots (.) are
 allowed in a domain name, the domain name can neither begin with nor end
 with a dash or dot, and additionally, two dashes or two dots in a row are
 not allowed and a dash followed by a dot or a dot followed by a dash are not
 allowed.
 
 So, I've come up with two regex's for checking domain names. The first one
 checks that the name contains alphanumerics, the dash and the dot, and
 neither begins with or ends with a dash or dot:
 
^[a-z0-9]$|^[a-z0-9]+[a-z0-9.-]*[a-z0-9]+$
 
 The second one checks that two dashes and two dots are not together and that
 a dash followed by a dot or a dot followed by a dash are not together:
 
--|\.\.|-\.|\.-
 
 Putting it all together, the way I check for a valid domain name is with the
 following:
 
if (eregi(^[a-z0-9]$|^[a-z0-9]+[a-z0-9.-]*[a-z0-9]+$, $domain_name) !=
 true
   OR eregi(--|\.\.|-\.|\.-, $domain_name) == true
{
   error;
}
 
 So, my question (finally!) is this:
 
 Is there any way to combine both expressions (basically, one part that
 checks for false and one part that checks for true) into one regex that just
 returns true or false?  I haven't been able to find any documentation that
 shows me how to do that, basically a like this but not like this syntax.
 
 BTW, anticipating someone mentioning the fact that the above regex's don't
 check for a domain name ending with a dot followed by three characters max
 (as in .com, .net, etc.), it's because that long-held truth is no longer
 true.  We now have .info and .museum, and who know what the future will
 bring.
 
 About the only truth left is that domain names end in a dot followed by two
 characters minimum (there are the country code domains like .us, .de. etc.
 but there are no one character TLD's at present and I would expect perhaps
 not for a long long time, but you never know).  Perhaps someone would expand
 on the regex above to include checking for a name ending with a dot followed
 by two characters minimum, I just haven't been into regex's long enough to
 know how).
 
 Of course, you could get really anal about all this and check for domain
 names that only end in the current ICANN root server TLD's (about 260 or so,
 I believe), but that wouldn't account for TLD's that operate within other
 root servers (there's always sumthin').  Anyways,
 
 Any help with the above is certainly appreciated!
 
 Jeff
 
 
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] regex help

2001-07-17 Thread Lasse


I think he means swap...

--
Lasse

Jack Dempsey [EMAIL PROTECTED] wrote in message
000601c10e81$03aca260$22ebd73f@2pqjp01">news:000601c10e81$03aca260$22ebd73f@2pqjp01...
 What exactly are you trying to do? Switch around in what way?

 Jack

 -Original Message-
 From: Alvin Tan [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, July 17, 2001 12:43 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP] regex help

 hi all,

 a little OT here, but need some quick help. I have a bunch of e-mails to

 convert into sql entries and I'm stuck here.

 I have:

   , John Doe, [EMAIL PROTECTED], ..

 I just need to know what's the regex to switch around the name and
 e-mail
 address.

 TIA,
 @lvin


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] regex help

2001-07-16 Thread Jack Dempsey

What exactly are you trying to do? Switch around in what way?

Jack

-Original Message-
From: Alvin Tan [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, July 17, 2001 12:43 AM
To: [EMAIL PROTECTED]
Subject: [PHP] regex help

hi all,

a little OT here, but need some quick help. I have a bunch of e-mails to

convert into sql entries and I'm stuck here.

I have:

  , John Doe, [EMAIL PROTECTED], ..

I just need to know what's the regex to switch around the name and
e-mail 
address.

TIA,
@lvin


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Regex Help

2001-07-13 Thread Erick Calder

Sheridan,

I didn't test this in PHP, I'm more familiar with the Perl Regex, but this
might work for you, play with it:

/img\s*src=([^ ]*)/

note: \s = whitespace and the [^ ] means any nonspace character... the only
issue remaining that you might find s or 's around the string matched into
the ().

- e r i c k

-Original Message-
From:   Sheridan Saint-Michel [mailto:[EMAIL PROTECTED]]
Sent:   Friday, July 13, 2001 9:04 AM
To: [EMAIL PROTECTED]
Subject:[PHP] Regex Help

I am trying to write a script that needs a list of all the images in an HTML
file.

I am trying this code

if (eregi ((img.+src=)(.+)[\s],$buffer, $regs ))
{
  echo $regs[2]BRBR;
}

The problem, however is that when it looks at

IMG SRC=images/Logo.gif ALT=Only Child Club - The Place for Only
Children

instead of getting images/Logo.gif like I want I am getting

images/Logo.gif ALT=Only Child Club - The Place for Only Children

I am not as familiar with Regexes as I would like and any help would be
greatly appreciated

Thanks

Sheridan Saint-Michel
Website Administrator
FoxJet, an ITW Company
www.foxjet.com


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] regex help...again

2001-03-30 Thread Christian Reiniger

On Friday 30 March 2001 06:47, you wrote:
 Ok, i have a text file with lines that looks like this:

 14```value```value2`value3

 This would be fine, except...there are sometimes more  than in
 other columns, so id like it to be

 14``value``value2``value3

$new = preg_replace ('/`+/', '``', $old);

quite simple, eh?

-- 
Christian Reiniger
LGDC Webmaster (http://sunsite.dk/lgdc/)

"World domination. Fast." (Linus Torvalds about Linux)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




  1   2   >