473,396 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Easy Regex

I've done alot of searching and can't seem to find this simple
replacement for table tags.

The end result is that I need to replace <td ABUNCHOFNONSENSEwith
<td>

Here's what I have now:

preg_replace('/^<td.+>/','<td>',$content);

It seems to do nothing, so I assume my pattern isn't matching anything.
Jul 9 '08 #1
3 1138
Chris wrote:
I've done alot of searching and can't seem to find this simple
replacement for table tags.

The end result is that I need to replace <td ABUNCHOFNONSENSEwith
<td>

Here's what I have now:

preg_replace('/^<td.+>/','<td>',$content);
Perhaps:

$content = preg_replace('/^<td.+>/','<td>',$content);

and perhaps you don't want to match at the start of $content with "^"

You may also wish to use the g and i switches.

Jeff
>
It seems to do nothing, so I assume my pattern isn't matching anything.
Jul 9 '08 #2
Chris wrote:
I've done alot of searching and can't seem to find this simple
replacement for table tags.

The end result is that I need to replace <td ABUNCHOFNONSENSEwith
<td>

Here's what I have now:

preg_replace('/^<td.+>/','<td>',$content);

It seems to do nothing, so I assume my pattern isn't matching
anything.
Seems to work fine for me. I ran the following script:
<?php
$content = '<td ABUNCHOFNONSENSE>';
echo htmlentities(preg_replace('/^<td.+>/','<td>',$content));
?>

and the output in my browser was <td>
Jul 9 '08 #3
Greetings, Chris.
In reply to Your message dated Wednesday, July 9, 2008, 23:11:44,
I've done alot of searching and can't seem to find this simple
replacement for table tags.
The end result is that I need to replace <td ABUNCHOFNONSENSEwith
<td>
Here's what I have now:
preg_replace('/^<td.+>/','<td>',$content);
It seems to do nothing, so I assume my pattern isn't matching anything.
There is no simple solution, but what you are trying is not correct one in any
case.
It will result in '<td>' on a string '<td>somestuff</td>'.
I myself would try something like this:

preg_replace('#<(list|of|tags)(?:\s+\w+\=(?:\"[^\"]+\"|\'[^\']+\'|\S+))*\s*>#i', '<$1>', $content);
--
Sincerely Yours, AnrDaemon <an*******@freemail.ru>

Jul 10 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mike King | last post by:
What RegEx will match the following? "abc.htm" 'cba.htm' acb.htm P.S. I just want the link without the quotes.
6
by: Jeff | last post by:
Hi, I'm finishing up developing a speech control jukebox (see intelligentjukebox.com) Can anyone point me to the easiest to use free library that does very basic regular expression matching...
1
by: Oren Liebermann | last post by:
I'm parsing through the HTML for an nba box score looking to pull out the officials' names, but the regex expression I'm using is pulling out the officials and all the code after the officials,...
2
by: DevDave | last post by:
Does anyone know of a quick method to extract just the numeric portion of a string without looping through each character? For instance: 674h23i -> 67423 23-112 -> 23112 87 (21) -> 8721...
6
by: Extremest | last post by:
I have a huge regex setup going on. If I don't do each one by itself instead of all in one it won't work for. Also would like to know if there is a faster way tried to use string.replace with all...
7
by: Extremest | last post by:
I am using this regex. static Regex paranthesis = new Regex("(\\d*/\\d*)", RegexOptions.IgnoreCase); it should find everything between parenthesis that have some numbers onyl then a forward...
5
by: sb | last post by:
Hello, I have a text file which contains plain text with the normal carriage-return/linefeed line terminators. With that file I want to find any occurence of "%R" (case-sensitive) on any line...
7
by: SteveM | last post by:
I am sure this is an easy question, but being relatively new to ASP.NET programming, I can not quite grasp what I need to accomplish what I need to do. What I have is a word document that is...
6
by: Peter Duniho | last post by:
So, I'm trying to learn how the Regex class works, and I've been trying to use it to do what I think ought to be simple things. Except I can't figure out how to do everything I want. :( If I...
5
by: DbZ | last post by:
Hi - i'm new to the regex thing - and trying to learn it to myself - Can someone please explain to me what the following line does - value.replace(/\s+$/g,"") I can kinda figure out its...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.