[PHP] RE: regex question

2005-05-17 Thread Carl Furst
I think there maybe a few ways to do this... One is

[EMAIL PROTECTED]@[EMAIL PROTECTED]

That basically says "find me the pattern where one non-at symbol is followed
by an at symbol followed by another non-at symbol"

So if you do 



numMatch: 3
Array
(
[0] => Array
(
[0] =>  @ 
[1] => i@ 
[2] => [EMAIL PROTECTED]
)

[1] => Array
(
[0] => @
[1] => @
[2] => @
)

)

Well, where that fails is when you have @'s at the beginning or end of the
string and that's easy enough to do.. So that would mean three searches...
There's probably a way to integrate them into one without loosing integrity,
but it depends on what kind of regexp libs you have, I reckon. It also
depends on what you really are trying to do with this search. Consider
str_replace, strpos and strtr as well.

Thanks,


Carl
-Original Message-
From: Al [mailto:[EMAIL PROTECTED] 
Sent: Monday, May 16, 2005 3:54 PM
To: php-general@lists.php.net
Subject: regex question

What pattern can I use to match ONLY single occurrences of a character in a
string.

e.g., "Some text @ and some mo@@re and [EMAIL PROTECTED], etc @@@.

I only want the two occurrences with a single occurrence of "@".

@{1} doesn't work; there are 4 matches.

Thanks

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



[PHP] Re: regex question?

2003-02-24 Thread Shawn McKenzie
Anyone?  please?

Thanks!
Shawn

"Shawn McKenzie" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I'm using the following to try and replace urls in my html output:
>
> $newhrefs = preg_replace("/script.php\?(.*)=(.*)&(.*)=(.*)&(.*)=(.*)/",
> "script-$1-$2-$3-$4-$5-$6.html", $hrefs);
>
> This works fine as long as there are exactly 3 var=val pairs... not 1 or 2
> or 4 or more...
>
> How can I write my expression to match 1 or more pairs???  For example:
>
> script.php?var=val
> script.php?var=val&var2=val2
> script.php?var=val&var2=val2&var3=val3
> etc...etc...etc...
>
> TIA,
> Shawn
>
>



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



[PHP] Re: Regex question

2002-12-12 Thread Paul Chvostek

On Thu, Dec 12, 2002 at 11:01:47PM -0800, Troy May wrote:
>
> How would take a regular non-formatted text link (http://www.link.com) and
> turn it into ready to post HTML? (href=http://www.link.com>http://www.link.com)
>
> Darn, Outlook formats it, but you get the idea.  It would just be typed out
> normally.

How about:

$href="(https?://([a-z0-9]+\.)+[a-z][a-z]+/[a-z0-9_./~%-]*)";
$repl="\\1";
$line=eregi_replace($href, $repl, $line);

You can of course make $href less restrictive if you're liberal minded
about your URL formats.

-- 
  Paul Chvostek <[EMAIL PROTECTED]>
  Operations / Abuse / Whatever  +1 416 598-
  it.canada - hosting and development  http://www.it.ca/


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




[PHP] Re: RegEx question

2002-07-03 Thread Tracker 1

"Richard Lynch" <[EMAIL PROTECTED]> wrote in message...
> > How can I regex to compare the last three chars of a string to "php"?
>
> if (substr($foo, -3) == 'php'){
> }
>
> Oh, wait, you wanted to use RegEx.  Sorry, can't help you there. :-)
>
> Don't use a cannon to swat a fly.

probably a good call.. :)

--
===
Michael J. Ryan  -  tracker1[*at*]theroughnecks.com
Roughneck BBS: http://www.theroughnecks.net  telnet://theroughnecks.net
===
Y!: aztracker1 - aim: azTracker1 - icq: 4935386 - msn: see email
One program for aim/icq/yahoo/msn/irc  -  http://www.trillian.cc/





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




[PHP] Re: RegEx question

2002-07-03 Thread Tracker 1

as a preg  "/(...)$/"

this gives you the last three chars..

--
===
Michael J. Ryan  -  tracker1[*at*]theroughnecks.com
Roughneck BBS: http://www.theroughnecks.net  telnet://theroughnecks.net
===
Y!: aztracker1 - aim: azTracker1 - icq: 4935386 - msn: see email
One program for aim/icq/yahoo/msn/irc  -  http://www.trillian.cc/


"David Busby" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> List,
> How can I regex to compare the last three chars of a string to "php"?
>
> /B
>



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




[PHP] Re: RegEx question

2002-07-02 Thread Richard Lynch

> How can I regex to compare the last three chars of a string to "php"?

if (substr($foo, -3) == 'php'){
}

Oh, wait, you wanted to use RegEx.  Sorry, can't help you there. :-)

Don't use a cannon to swat a fly.

-- 
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




[PHP] Re: Regex question

2001-07-31 Thread Andrew Sterling Hanenkamp

You're making your expressions too complicated. To test for just that 
string,

eregi("HTTP/1\.[01] 302", $output)

should work.

Later,
Sterling

Boaz Yahav wrote:

> I'm trying to find if a string exists inside a string. Instead of using
> strstr() twice I want to use eregi() once.
> 
> What I want to check is if "HTTP/1.1 302" or "HTTP/1.0 302" exists in
> some $output.
> 
> I'm trying something like : 
> 
> eregi("[\"HTTP/1.\"]+[0-1]+[\" 302\"]",$output)
> eregi("[HTTP/1.]+[0-1]+[ 302]",$output)
> eregi("HTTP/1.+[0-1]+ 302",$output)
> 
> But I must be off cause it doesn't work.
> 
> Anyone?
> 
> thanks
> 
> 
> berber
> 


-- 
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] Re: regex question

2001-07-16 Thread Philip Hallstrom

You could do it using the strpos() function to find the index of the first
occurance of "" and strrpos() for the last occurence.  Then use
substr()  to grab what you want...

On Mon, 16 Jul 2001, Julian Simpson wrote:

> I'm trying to parse an existing html file using php.
> I need to use regex to find the first (and only the first) occurance of 
> and the last (and only the last) occurance of  in a string.
> They will be replaced with ||.
>
> example of a string:
> blah blah some stuff that i need to get blah blah blah.
>
> needs to become:
> blah blah ||some stuff that i need to get|| blah blah blah.
>
> so the following is what i need.
> //replace outer tags with ||
> $string = ereg_replace ("Some regex that only finds the first ","||",$string);
> $string = ereg_replace ("Some regex that only finds the last ","||",$string);
> //take out remaining (inner) tags.
> $string = ereg_replace ("","",$string);
> $string = ereg_replace ("","",$string);
>
> thanks
>
> Julian
>
>
> --
> 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]