[PHP] regex help needed

2004-08-01 Thread Kathleen Ballard
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

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



[PHP] Regex help needed

2003-07-16 Thread Sid
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?

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

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)

Thanks in advance.

- Sid

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

2001-02-13 Thread PHPBeginner.com

try ereg_replace("^[ ]+(.)[ ]+$", '_\\1_', $here)

I haven't tested it, but if it won't work, then do this:

$here = ereg_replace("^[ ]+", '_', $here)
$here = ereg_replace("[ ]$", '_', $here)

this should work...

Sincerely,

 Maxim Maletsky
 Founder, Chief Developer

 PHPBeginner.com (Where PHP Begins)
 [EMAIL PROTECTED]
 www.phpbeginner.com




-Original Message-
From: Jesse Swensen [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 13, 2001 4:39 AM
To: PHPBeginner.com
Subject: Re: [PHP] Regex help needed...


Thank you for your suggest, but I don't want to just trim them, I need to
display them as underscores (_).
--
Jesse Swensen
[EMAIL PROTECTED]

 From: "PHPBeginner.com" [EMAIL PROTECTED]
 Date: Tue, 13 Feb 2001 03:25:59 +0900
 To: "Jesse Swensen" [EMAIL PROTECTED], [EMAIL PROTECTED]
 Subject: RE: [PHP] Regex help needed...

 rtrim()

 www.php.net/rtrim


 Sincerely,

 Maxim Maletsky
 Founder, Chief Developer

 PHPBeginner.com (Where PHP Begins)
 [EMAIL PROTECTED]
 www.phpbeginner.com





 -Original Message-
 From: Jesse Swensen [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, February 13, 2001 2:15 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Regex help needed...


 This should be a quick one, but I can't seem to wrap my brain around it.
 All I need to do is replace leading or trailing spaces with underscores.
If
 there is spaces in between words, leave them alone.

 Suggestions?

 --
 Jesse Swensen
 [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 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 help needed...

2001-02-12 Thread Jesse Swensen

This should be a quick one, but I can't seem to wrap my brain around it.
All I need to do is replace leading or trailing spaces with underscores.  If
there is spaces in between words, leave them alone.

Suggestions?

-- 
Jesse Swensen
[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 needed...

2001-02-12 Thread Jason Stechschulte

On Mon, Feb 12, 2001 at 12:15:04PM -0500, Jesse Swensen wrote:
 This should be a quick one, but I can't seem to wrap my brain around it.
 All I need to do is replace leading or trailing spaces with underscores.  If
 there is spaces in between words, leave them alone.

$fix = ereg_replace("(^ )|( $)", "_", $checkme);

-- 
Jason Stechschulte
[EMAIL PROTECTED]
--
/* This bit of chicanery makes a unary function followed by
a parenthesis into a function with one argument, highest precedence. */
 -- Larry Wall in toke.c from the perl source code

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

2001-02-12 Thread PHPBeginner.com

rtrim()

www.php.net/rtrim


Sincerely,

 Maxim Maletsky
 Founder, Chief Developer

 PHPBeginner.com (Where PHP Begins)
 [EMAIL PROTECTED]
 www.phpbeginner.com





-Original Message-
From: Jesse Swensen [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 13, 2001 2:15 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Regex help needed...


This should be a quick one, but I can't seem to wrap my brain around it.
All I need to do is replace leading or trailing spaces with underscores.  If
there is spaces in between words, leave them alone.

Suggestions?

--
Jesse Swensen
[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 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 needed...

2001-02-12 Thread Jesse Swensen

on 2/12/01 1:01 PM, Jason Stechschulte at [EMAIL PROTECTED] wrote:

 On Mon, Feb 12, 2001 at 12:15:04PM -0500, Jesse Swensen wrote:
 This should be a quick one, but I can't seem to wrap my brain around it.
 All I need to do is replace leading or trailing spaces with underscores.  If
 there is spaces in between words, leave them alone.
 
 $fix = ereg_replace("(^ )|( $)", "_", $checkme);

This is very close.  If the string, "  Testing  ", had multiple spaces, but
I wanted to convert each space to a "_", then what?  I tried:

$fix = ereg_replace("(^ +)|( +$)", "_", $checkme);

and

$fix = ereg_replace("(^[ ]+)|([ ]+$)", "_", $checkme);

with no success.

Thanks for your help...
-- 
Jesse Swensen
[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 needed...

2001-02-12 Thread Jason Stechschulte

 This is very close.  If the string, "  Testing  ", had multiple spaces, but
 I wanted to convert each space to a "_", then what?  I tried:

There may be a better way, but here is a lengthy one that works.

$checkme = "  this is  it   ";

if(ereg("^( )+", $checkme, $match)) {
   for($i = 0; $i  strlen($match[0]); $i++) {
  $start .= "_";
   }
}
if(ereg("( )+$", $checkme, $match)) {
   for($i = 0; $i  strlen($match[0]); $i++) {
  $end .= "_";
   }
}

$fix = ereg_replace("^( )+", $start, $checkme);
$fix = ereg_replace("( )+$", $end, $fix);

echo "$fix";

-- 
Jason Stechschulte
[EMAIL PROTECTED]
--
How do Crays and Alphas handle the POSIX problem?
 -- Larry Wall in [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 needed...

2001-02-12 Thread Jesse Swensen

on 2/12/01 4:30 PM, Christian Reiniger at [EMAIL PROTECTED] wrote:

 On Monday 12 February 2001 21:08, Jesse Swensen wrote:
 This should be a quick one, but I can't seem to wrap my brain around
 it. All I need to do is replace leading or trailing spaces with
 underscores.  If there is spaces in between words, leave them alone.
 but I wanted to convert each space to a "_", then what?  I tried:
 
 $fix = ereg_replace("(^ +)|( +$)", "_", $checkme);
 
 and
 
 $fix = ereg_replace("(^[ ]+)|([ ]+$)", "_", $checkme);
 
 preg_match ('/^(\s*)(.*?)(\s*)$/', $checkme, $matches);
 $NewString = str_repeat ('_', strlen ($matches [1])).
 $matches [2] .
 str_repeat ('_', strlen ($matches [3]));
 
 not tested, but should work fine.

That worked.  Thank you very much.
-- 
Jesse Swensen
[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]