RE: [PHP] Regex question: replacing incidences of character when not enclosed within HTML tags? (somewhat solved)

2005-05-29 Thread Murray @ PlanetThoughtful
 So, thinking about it a little more, I decided what I was looking for was
 a
 regular expression that would allow me to replace any incidences of
 hyphens
 when not contained within tags (i.e., when not contained between  and
 ).
 
 And this is where things have ground to a halt.

Hi All,

After toying with this for several hours I decided to give up on trying to
work out a way to achieve this via a single regular expression replacement.

My simpler 'solution' now is to pull out all text not contained within tags
using preg_match_all(), and run a str_replace() across these values to
replace any incidences of hyphens, and then another str_replace() to replace
the content with the substring where hyphens were found.

So, something like:

?
preg_match_all(/(^|)(.+?)(|$)/m, $text,$hypharr);
for ($i=0; $i  count($hypharr[0]); $i++){

$rephyph = str_replace(-,-span style='font-size: 0px;'
/span, $hypharr[0][$i]);
if ($rephyph  $hypharr[0][$i]){
$text= str_replace($hypharr[0][$i],$rephyph,$text);
}
}

?

This seems to achieve what I'm looking for, ie replacing hyphens when not
contained in HTML tags.

Regards,

Murray

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



[PHP] Regex question: replacing incidences of character when not enclosed within HTML tags?

2005-05-28 Thread Murray @ PlanetThoughtful
Hi All,

I have content that contains several lengthy hyphenated sentences, such as:

This-is-a-sentence-in-which-all-the-words-are-hyphenated.

I've noticed that some (maybe all?) browsers, particularly Firefox, will not
wrap long strings of hyphenated words when they are contained in a DIV tag
-- instead, the sentence simply runs out across the right border of the DIV
and overlaps any content to the right.

After some experimentation, I discovered that a hack that seems to behave
well in Firefox, Opera, and IE6 is to replace all incidences of the hyphen
(-) character with -span style='font-size:0px;' /span. This
effectively creates a zero-width space character after each hyphen and
allows the sentence to wrap as desired.

My dilemma is that while I want to replace any hyphens with the above hack
when and where they appear within normal sentences, I don't want to replace
them when and where they appear within HTML tags.

So, imagine I have a string that contains:

div style='text-decoration: none;
font-size:11px;'This-is-a-sentence-that-contains-hyphenation. This is a
sentence that doesn't contain hyphenation. This is a a
href='http://www.nowhere.com/-4484784/index.html'link/a that will take
you span style='font-weight: bold;'nowhere/span./div

I managed to build a replacement regular expression that would ignore any
hyphenated strings that were terminated by a colon (:) character (which
effectively leaves inline style attributes in DIV and SPAN blocks
untouched).

?
$thingy = preg_replace(/(-)(?![\w-]+?:)/i, \$1span
style='font-size:0px;' /span, $whatever); ?

This seemed to work well in most circumstances, however, in testing I
discovered several incidences of a href= urls that also contain hyphens
(in particular, some that lead to Amazon.com).

So, thinking about it a little more, I decided what I was looking for was a
regular expression that would allow me to replace any incidences of hyphens
when not contained within tags (i.e., when not contained between  and
). 

And this is where things have ground to a halt.

I'm wondering if anyone can give me some help with this? I've tried to find
a solution via google, but most regex examples dealing with HTML tags are
concerned with finding tags and their contents, not with finding specific
instances of characters not contained within tags.

Any help appreciated!

Much warmth,

Murray

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



Re: [PHP] regex question

2005-05-17 Thread Petar Nedyalkov
On Monday 16 May 2005 22:53, Al wrote:
 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 @@@.

Use the following:

/(^@)(@{1})(^@)/

This way you'll be sure the regexp will match only single occurences ot hte 
'@' symbol.
Please take in mind that if you have this symbol in the beginning of the 
string or at the end - you have to modify this.


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

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

 Thanks

-- 

Cyberly yours,
Petar Nedyalkov
Devoted Orbitel Fan :-)

PGP ID: 7AE45436
PGP Public Key: http://bu.orbitel.bg/pgp/bu.asc
PGP Fingerprint: 7923 8D52 B145 02E8 6F63 8BDA 2D3F 7C0B 7AE4 5436


pgpWSAkSaWAeD.pgp
Description: PGP signature


Re: [PHP] regex question

2005-05-17 Thread Al
Murry's solution here is ideal since it only captures the single occurrence. 
Since I want to use it for a preg_replace(), it is perfect.

A couple of folks sent this pattern [EMAIL PROTECTED]@[EMAIL PROTECTED]; but, it doesn't work because I 
then have to remove the unwanted caracters on either side.

All it says is [not  @[EMAIL PROTECTED]@] but, it captures the 2 characters on 
each side.
Murry's solution (?!@)@(?!@) is good since it only captures the @
Thanks everyone


Murray @ PlanetThoughtful wrote:
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

Please ignore my last email re: your question. I realized that the negation
of the range containing the @ would end up capturing unwanted characters.
As an alternative, try the following:
preg_match_all('/(?!@)@(?!@)/','Some @ text with the @t sym@@bol  ',
$thing, PREG_OFFSET_CAPTURE); 

print_r($thing);
Hope that's a little more relevant to your question.
Regards,
Murray
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] regex question

2005-05-16 Thread Al
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


Re: [PHP] regex question

2005-05-16 Thread Brandon Ryan
Try (for example if character was A) ...

([^A]|^)A([^A]|$)

This matches four cases:
A is at beginning of string and there is another letter after it,
A has a letter before it and a letter after it,
A is at end of string and there is a letter before it,
or A is the only character in the string.

On 5/16/05, Al [EMAIL PROTECTED] wrote:
 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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] regex question

2005-05-16 Thread Philip Hallstrom
On Mon, 16 May 2005, Al wrote:
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 @.
[EMAIL PROTECTED]@[EMAIL PROTECTED]
should do it I think.
@{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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] regex question

2005-05-16 Thread Murray @ PlanetThoughtful
 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.

/[EMAIL PROTECTED]@[EMAIL PROTECTED]/ seems to do what you're looking for. In 
other words, match the
@ symbol where it is not preceded or followed by another @ symbol.

To test, try:

preg_match_all('/[EMAIL PROTECTED]@[EMAIL PROTECTED]/','Some @ text with the @t 
sym@@bol  @@@',
$thing, PREG_OFFSET_CAPTURE); 

print_r($thing);

There may be a more intuitive way to do this, but at least it seems to work.

Regards,

Murray

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



RE: [PHP] regex question

2005-05-16 Thread Murray @ PlanetThoughtful
 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

Please ignore my last email re: your question. I realized that the negation
of the range containing the @ would end up capturing unwanted characters.

As an alternative, try the following:

preg_match_all('/(?!@)@(?!@)/','Some @ text with the @t sym@@bol  ',
$thing, PREG_OFFSET_CAPTURE); 

print_r($thing);

Hope that's a little more relevant to your question.

Regards,

Murray

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



RE: [PHP] regex question

2005-05-16 Thread Murray @ PlanetThoughtful
 Try (for example if character was A) ...
 
 ([^A]|^)A([^A]|$)
 
 This matches four cases:
 A is at beginning of string and there is another letter after it,
 A has a letter before it and a letter after it,
 A is at end of string and there is a letter before it,
 or A is the only character in the string.

I think this has the same problem that my first attempt at this regex
experienced.

I.e., it will correctly 'find' single instances of 'A', but it will 'match'
against unwanted characters on either side of each 'found' 'A' because they
are not-A.

For example, the following:

preg_match_all('/([^A]|^)A([^A]|$)/','A sentence with instAnces of AAA
chArActers', $thing, PREG_OFFSET_CAPTURE);

print_r($thing);

produces:

Array
(
[0] = Array
(
[0] = Array
(
[0] = A
[1] = 0
)

[1] = Array
(
[0] = tAn
[1] = 19
)

[2] = Array
(
[0] = hAr
[1] = 34
)

)

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

[1] = Array
(
[0] = t
[1] = 19
)

[2] = Array
(
[0] = h
[1] = 34
)

)

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

[1] = Array
(
[0] = n
[1] = 21
)

[2] = Array
(
[0] = r
[1] = 36
)

)

)

Note the multiple instances of characters other than 'A' in the array. Also
note that the 4th qualifying 'A' (the second 'A' in 'chArActers') is missed,
because the 'r' is already part of the capture of the preceding 'A').

On the other hand, the following:


preg_match_all(' /(?!A)A(?!A)/','A sentence with instAnces of AAA
chArActers', $thing, PREG_OFFSET_CAPTURE);

print_r($thing);

produces:

Array
(
[0] = Array
(
[0] = Array
(
[0] = A
[1] = 0
)

[1] = Array
(
[0] = A
[1] = 20
)

[2] = Array
(
[0] = A
[1] = 35
)

[3] = Array
(
[0] = A
[1] = 37
)

)

)

Here, only the target characters are matched, without the confusion of extra
unwanted characters. All 4 target 'A's are caught, because the patterns on
either side of the 'A' in the regex pattern are non-capturing. So, basically
this is employing a non-capturing negative look-behind and a non-capturing
negative look-ahead, rather than capturing negated character classes.

I've probably only managed to confuse things more than they were, but I'm
hoping some of what I've said above makes sense (to me, if no-one else).

Regards,

Murray

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



Re: [PHP] regex question

2005-05-16 Thread Jason Barnett
?php
$text = 'Some text @ and some mo@@re and [EMAIL PROTECTED], etc @@@.';
/** Word boundaries before and after @ */
$regex = '/[EMAIL PROTECTED]/';
preg_match_all($regex, $text, $matches);
var_dump($matches);
?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] REGEX Question

2003-06-18 Thread Don Read

On 17-Jun-2003 Ron Dyck wrote:
 I need to match text between two html comment tags.
 
 I'm using: preg_match(/!--start_tag--(.*)!--end_tag--/, $data,
 $Match)
 
 Which work fine until I have carriage returns. The following doesn't
 match:
 

Use the m (multiline) modifier:

preg_match(/!--start_tag--(.*)!--end_tag--/m, ...

Regards,
-- 
Don Read   [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to 
   steal the neighbor's newspaper, that's the time to do it.
   

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



Re: [PHP] REGEX Question

2003-06-18 Thread SLanger
Hello

Two things:
First wouldn't it be faster to use strpos and substr if you simply have to 
find the literate !-- start_tag -- and !-- end_tag --.
Second: If you use your regex and you have something like
!-- start_tag -- This is some text to grasp!-- end_tag -- this is 
text I don't want !-- start_tag -- This is some other text I want!-- 
end_tag --
The result would be  This is some text to grasp!-- end_tag -- this is 
text I don't want !-- start_tag -- This is some other text I want. 
You should use the  *+ quantifier in order to only grab the content  
This is some text to grasp. 

Regards
Stefan Langer

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



[PHP] REGEX Question

2003-06-17 Thread Ron Dyck
I need to match text between two html comment tags.

I'm using: preg_match(/!--start_tag--(.*)!--end_tag--/, $data, $Match)

Which work fine until I have carriage returns. The following doesn't match:

!--start_tag-- Nullam auctor pellentesque sem. Aenean semper. Aenean magna
justo, rutrum et, consequat a, vehicula non, arcu.

Mauris cursus vulputate pede. Cum sociis natoque penatibus et magnis dis
parturient montes, nascetur ridiculus mus. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit.!--end_tag--


Appreciate you help.

==
Ron Dyck
Webbtech.net
==


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



Re: [PHP] REGEX Question

2003-06-17 Thread Marek Kilimajer
. matches any character except newline by default, use s modifier:
preg_match(/!--start_tag--(.*)!--end_tag--/s, $data, $Match)
Ron Dyck wrote:
I need to match text between two html comment tags.

I'm using: preg_match(/!--start_tag--(.*)!--end_tag--/, $data, $Match)

Which work fine until I have carriage returns. The following doesn't match:

!--start_tag-- Nullam auctor pellentesque sem. Aenean semper. Aenean magna
justo, rutrum et, consequat a, vehicula non, arcu.
Mauris cursus vulputate pede. Cum sociis natoque penatibus et magnis dis
parturient montes, nascetur ridiculus mus. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit.!--end_tag--
Appreciate you help.

==
Ron Dyck
Webbtech.net
==



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


[PHP] regex question?

2003-02-23 Thread Shawn McKenzie
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=valvar2=val2
script.php?var=valvar2=val2var3=val3
etc...etc...etc...

TIA,
Shawn



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



Re: [PHP] Regex question

2002-12-13 Thread Sean Burlington
Troy May wrote:

How would take a regular non-formatted text link (http://www.link.com) and
turn it into ready to post HTML? (a
href=http://www.link.comhttp://www.link.com/a)

Darn, Outlook formats it, but you get the idea.  It would just be typed out
normally.

Any ideas?




function MakeUrl ($text) {
$text =  preg_replace(/(www\.[a-zA-Z0-9\.\/#~:?+=%@!_\\-]+)/, 
http://\\1;  ,$text);#make www. - http://www.
$text = 
preg_replace(/(http:\/\/)(?!www)([a-zA-Z0-9\.\/#~:?+=%@!_\\-]+)/, 
\\1\\2  ,$text); #eg-- http://kernel.org
$text = 
preg_replace(/(http:\/\/)(www\.)([a-zA-Z0-9\.\/#~:?+=%@!\\-_]+)/, 
\\1\\2\\3 ,$text); #eg -- http://www.google.com - a 
hrefhttp://www.google.com;www.google.com/a
return $text;
}


--

Sean


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



[PHP] Regex question

2002-12-12 Thread Troy May
How would take a regular non-formatted text link (http://www.link.com) and
turn it into ready to post HTML? (a
href=http://www.link.comhttp://www.link.com/a)

Darn, Outlook formats it, but you get the idea.  It would just be typed out
normally.

Any ideas?


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




[PHP] Regex question...

2002-10-28 Thread Leif K-Brooks
In my never-ending battle against swearing on my site, I'm trying to use 
a regex that changes any word that ends with abc to xyz.  I'm using:

$tofilter = This is a string containing the word 123abc.;
$tofilter=  eregi_replace([^ ]abc,xyz,$tofilter);

But it returns 12xyz.  It clearly picks up 3abc before 123abc. 
I've also tried two regexes that check for it as a seperate word and at 
the begining of the string using

$tofilter = This is a string containing the word 123abc.;
$tofilter=  eregi_replace( [^ ]abc,xyz,$tofilter);
$tofilter=  eregi_replace(^[^ ]abc,xyz,$tofilter);

But that doesn't work at all.  Any ideas on how to do this?

--
The above message is encrypted with double rot13 encoding.  Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law.



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



Re: [PHP] Regex question...

2002-10-28 Thread @ Edwin
Hello,

Leif K-Brooks [EMAIL PROTECTED] wrote:
[snip] 
 But that doesn't work at all.  Any ideas on how to do this?
[/snip]

Would't it be easier (and faster) to use

   http://www.php.net/manual/en/function.str-replace.php ?

- E


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




Re: [PHP] Regex question...

2002-10-28 Thread Leif K-Brooks
I need to do a few other things that require regex though, like making 
either an a or an @ match (people love to get around filters by using 
symbols instead of letters...).

@ Edwin wrote:

Hello,

Leif K-Brooks [EMAIL PROTECTED] wrote:
[snip] 
 

But that doesn't work at all.  Any ideas on how to do this?
   

[/snip]

Would't it be easier (and faster) to use

  http://www.php.net/manual/en/function.str-replace.php ?

- E


 


--
The above message is encrypted with double rot13 encoding.  Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law.





[PHP] RegEx question

2002-07-02 Thread David Busby

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




Re: [PHP] RegEx question

2002-07-02 Thread Kevin Stone

Actually for a job like this look to substr() to extract the last three
chars as a string and compare them in an if() statment.
http://www.php.net/manual/en/function.substr.php
-Kevin

- Original Message -
From: David Busby [EMAIL PROTECTED]
To: php-general [EMAIL PROTECTED]
Sent: Tuesday, July 02, 2002 2:49 PM
Subject: [PHP] RegEx question


 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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] RegEx question

2002-07-02 Thread Henning Sittler

$string = 'somethingphp';
$pat = 'php$';
$hasphp = ereg($pat, $string);



Henning Sittler
www.inscriber.com



-Original Message-
From: David Busby [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 02, 2002 4:49 PM
To: php-general
Subject: [PHP] RegEx question


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



Re: [PHP] RegEx question

2002-07-02 Thread Gurhan Ozen

eregi(php$, $stringtobecompared);

See: http://www.php.net/manual/en/ref.regex.php

Gurhan

- Original Message - 
From: David Busby [EMAIL PROTECTED]
To: php-general [EMAIL PROTECTED]
Sent: Tuesday, July 02, 2002 4:49 PM
Subject: [PHP] RegEx question


 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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Regex question

2002-01-09 Thread Jon Haworth

Hi all,

I've got a regex that's working fine, apart from one little problem. 

$tags = array (script,
   !--!\[CDATA\[,
   \]\]--);
foreach ($tags as $currentTag)
  if (preg_match (/^\/. $currentTag. /, $content)) 
// do something

(checking to see if anything in the $tags array is at the start of the
string)

The problem is that it's not picking up !--![CDATA[ and ]]--. I've
escaped the [ and ] as I know they're reserved in regexes, but it seems
there's something else that needs escaping or otherwise tweaking, and all
manner of experimentation has proved fruitless :-(

Can anyone help me out?

Cheers
Jon


Witan Jardine
13 Southampton Place
London WC1A 2AL
Tel: 020 7404 4004

Please visit us on the Internet:
http://www.witanjardine.co.uk/

The information included in this e-mail is of a confidential nature and is
intended only for the addressee.  If you are not the intended addressee, any
disclosure, copying or distribution by you is prohibited and may be
unlawful.  Disclosure to any party other than the addressee, whether
inadvertent or otherwise is not intended to waive privilege of
confidentiality.

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

2002-01-09 Thread Stefan Rusterholz

 Hi all,

 I've got a regex that's working fine, apart from one little problem.

 $tags = array (script,
!--!\[CDATA\[,
\]\]--);

A quick shot (perhaps I miss the point ;): if you do
$x = \[;
then $x will contain [. If you then do a regex with preg_match(/$x/,
... eg. then it get's evaluated as preg_match(/[/, ...
If you want the [ to be escaped in the regex you have to double-escape it:
$x = \ \[; (sorry, the two \ should be together without a space but my
stupid mail-app converts the string thinking it's an network address)
so $x will contain \[ as you want ( the first backslash escapes the
second).

 foreach ($tags as $currentTag)
   if (preg_match (/^\/. $currentTag. /, $content))
 // do something


 Witan Jardine
 13 Southampton Place
 London WC1A 2AL
 Tel: 020 7404 4004

I hope I didn't miss the point and could help you
best regards
Stefan Rusterholz


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

2002-01-09 Thread Jon Haworth

 If you want the [ to be escaped in the regex you have to double-escape
it:
 $x = \ \[; (sorry, the two \ should be together without a space but my
 stupid mail-app converts the string thinking it's an network address)
 so $x will contain \[ as you want ( the first backslash escapes the
 second).

Hi Stefan,

Thanks very much for that, it does make sense :-)

Unfortunately it still hasn't fixed the problem... I suppose my question has
now boiled down to do I need to escape !, , or - in a regex? :-)

Cheers
Jon


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

2002-01-09 Thread Stefan Rusterholz


  If you want the [ to be escaped in the regex you have to double-escape
 it:
  $x = \ \[; (sorry, the two \ should be together without a space but my
  stupid mail-app converts the string thinking it's an network address)
  so $x will contain \[ as you want ( the first backslash escapes the
  second).

 Hi Stefan,

 Thanks very much for that, it does make sense :-)

 Unfortunately it still hasn't fixed the problem... I suppose my question
has
 now boiled down to do I need to escape !, , or - in a regex? :-)

 Cheers
 Jon

here the expression again:
$tags = array (script,
   !--!\[CDATA\[,
   \]\]--);
foreach ($tags as $currentTag)
  if (preg_match (/^\/. $currentTag. /, $content))
   // do something

As far as I can see (notice: I'm not a regex-king ;) the regex seems correct
to me. The only thing I'm wondering about is the /^ (second last line of
the citation). Together with your expression in the array it results in
preg_match(/\/!\[CDATA\[/, ...)
I'm wondering if that (/![CDATA...) is really what you want to match (and
not only ![CDATA without the trailing /).

If it's not that then I suggest you to do simple example scripts where you
have none-dynamic regex's to test if the expression works (that's the way I
do that stuff - no really because I ever think I'd THIS TIME be able to do
it without, but I haven't thought right till today ;)

lot of luck mastering your expressions
stefan rusterholz


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

2002-01-09 Thread Jon Haworth

 As far as I can see (notice: I'm not a regex-king ;) the regex seems
correct
 to me. The only thing I'm wondering about is the /^ (second last line
of
 the citation). Together with your expression in the array it results in
 preg_match(/\/!\[CDATA\[/, ...)
 I'm wondering if that (/![CDATA...) is really what you want to match
(and
 not only ![CDATA without the trailing /).


Aaarrgh thump thump thump thump thump

That's it! Thanks very much Stefan. 

It's trying to match a closing HTML tag, but of course that doesn't apply to
CDATA, so it all went pear-shaped. I stared at that bloody regex for hours,
as well sigh

Cheers
Jon







-- 
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] Regex question

2001-07-31 Thread Boaz Yahav

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]




RE: [PHP] Regex question

2001-07-31 Thread Boaz Yahav

In case anyone is interested, eregi(HTTP/1.[01].302,$output) seems to
work :)

berber

-Original Message-
From: Boaz Yahav 
Sent: Tuesday, July 31, 2001 2:03 PM
To: PHP General (E-mail)
Subject: [PHP] Regex question


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

2001-07-16 Thread Julian Simpson

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 i
and the last (and only the last) occurance of /i in a string. 
They will be replaced with ||.

example of a string:
blah blah isome stuff/i that i ineed to get/i 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 i,||,$string);
$string = ereg_replace (Some regex that only finds the last /i,||,$string);
//take out remaining (inner) tags.
$string = ereg_replace (i,,$string);
$string = ereg_replace (/i,,$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]




Re: [PHP] RegEx Question

2001-05-21 Thread Gyozo Papp


if (preg_match_all(|testing(.*?);blah|s, $str, $matches))
{
// do what you want with $matches: see in the manual!
 var_dump($matches);
}

- Original Message - 
From: George E. Papadakis [EMAIL PROTECTED]
To: PHP List [EMAIL PROTECTED]
Sent: 2001. május 20. 19:18
Subject: [PHP] RegEx Question


 Hi,
 
 I have an ereg question::.
 $data = a big string ,
 while (ereg (testing([^;]*);blah(.*),$data,$args)) {
 $this = $args[1];
 $data = $args[2];
 }
 
 What I wanna do ,obviously, is to get all the strings between 'testng' and
 'blah' in an array.
 This will do it, yet when it wont work when special chars such \n exist
 between 'testing' and 'blah'.
 Any ideas?
 
 
 
 -- 
 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]




[PHP] RegEx Question

2001-05-20 Thread George E. Papadakis

Hi,

I have an ereg question::.
$data = a big string ,
while (ereg (testing([^;]*);blah(.*),$data,$args)) {
$this = $args[1];
$data = $args[2];
}

What I wanna do ,obviously, is to get all the strings between 'testng' and
'blah' in an array.
This will do it, yet when it wont work when special chars such \n exist
between 'testing' and 'blah'.
Any ideas?



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

2001-05-20 Thread Christian Reiniger

On Sunday 20 May 2001 19:18, George E. Papadakis wrote:

 I have an ereg question::.
 $data = a big string ,
 while (ereg (testing([^;]*);blah(.*),$data,$args)) {
 $this = $args[1];
 $data = $args[2];
 }

 What I wanna do ,obviously, is to get all the strings between 'testng'
 and 'blah' in an array.
 This will do it, yet when it wont work when special chars such \n exist
 between 'testing' and 'blah'.

Use preg_match() with 's' or 'm' as modifier (one of these is correct...)

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

The most exciting phrase to hear in science, the one that heralds new
discoveries, is not Eureka, but That's funny...

- Isaac Asimov

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