Page 1 of 1
Confusing Regular Expression
Posted: Thu Mar 11, 2004 5:22 pm
by chris12295
i need to split some text on this text: <tr style='mso-yfti-irow:0'>
or this text: <tr>
and also the same thing with <td>
but i cant figure out a good regular expression to use with split().
any ideas?
Posted: Thu Mar 11, 2004 9:12 pm
by Illusionist
so whats your question? your totally confused me....
Posted: Thu Mar 11, 2004 9:23 pm
by chris12295
my question is, what is a regular expression that will match a tr tag with variable stuff in it such as:
<tr width=100 height=100>
or
<tr bgcolor=#ffffff>
or
<tr>
etc...
I want to split up Table rows by the tr tag no matter what attributes are in the TR tag.
Posted: Thu Mar 11, 2004 9:44 pm
by Illusionist
so maybe something like:
Code: Select all
$regexp = "#\<tr.*?>(.*?)</tr>#is";
Posted: Thu Mar 11, 2004 10:15 pm
by Illusionist
try this:
Code: Select all
$trText = "<tr width=100 height=100>Here </tr><tr bgcolor=#ffffff>is some </tr><tr>TeXt</tr>";
$regexp = "#\<tr.*?>(.*?)</tr>#is";
$c = preg_match_all($regexp,$trText,$match);
for ($i=0; $i<$c; $i++) {
echo $match[0][$i];
}
//returns Here is Some TeXt
Posted: Thu Mar 11, 2004 11:46 pm
by chris12295
not quite what i need. I need a pattern for preg_split()
and also, i just want it to match a <tr> tag, NOT <tr>text</tr>
basically i need somthing like this <tr.*> except that is greedy (it will match everything until the last > in the document)
Posted: Fri Mar 12, 2004 6:16 am
by Illusionist
i dont understand what you need. sorry...
Posted: Fri Mar 12, 2004 6:43 am
by redmonkey
chris12295 wrote:
basically i need somthing like this <tr.*> except that is greedy (it will match everything until the last > in the document)
So why not use <tr.*?>
Posted: Fri Mar 12, 2004 10:15 am
by TheBentinel.com
chris12295 wrote:not quite what i need. I need a pattern for preg_split()
and also, i just want it to match a <tr> tag, NOT <tr>text</tr>
basically i need somthing like this <tr.*> except that is greedy (it will match everything until the last > in the document)
I am definitely not a regexp guy, but something related to [!<] might get you closer.
<tr[!<]*> maybe?
Shooting blind here, I never touch regexp's. They see me coming and start lining up their crosshairs on my foot.