473,503 Members | 544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

preg_replace regex

trying to clear out all text between the outermost

<---Message Start--->
and
<---Message End--->
tags
using snippet

$message=preg_replace("'<---Message[^>]*?>.*?End--->'si", "",$message);

should work fine ... but still returning crap ... not sure why

anyone a regex expert?
Jul 17 '05 #1
2 1943
brendan wrote:
trying to clear out all text between the outermost

<---Message Start--->
and
<---Message End--->
tags
using snippet

$message=preg_replace("'<---Message[^>]*?>.*?End--->'si",
"",$message);

should work fine ... but still returning crap ... not sure why


Simply apply the U(ngreedy) pattern modifier and simplify the pattern:

$str = preg_replace("/<---Message(.+)--->/Uis", "", $str);
JW

Jul 17 '05 #2
Janwillem Borleffs wrote:
brendan wrote:
trying to clear out all text between the outermost
Do you really mean 'between'?
<---Message Start--->
and
<---Message End--->
tags


[ ... ]
Simply apply the U(ngreedy) pattern modifier and simplify the pattern:

$str = preg_replace("/<---Message(.+)--->/Uis", "", $str);


That's the right idea, but a step too far. Remember that
PCRE_UNGREEDY inverts greediness; the plus sign in your
pattern isn't greedy, so the dot stops matching at the first
'--->'. All '<---Message Start--->' and '<---Message End--
->' tags are removed.

You want it to stop after the last '--->' of the final '<---
Message End--->'. The quantifier should be greedy; e.g.,

`<---Message Start--->.*<---Message End--->`s

HAGW JW!

--
Jock
Jul 17 '05 #3

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

Similar topics

3
2972
by: Justin Koivisto | last post by:
I am replacing a string in a text block that has a literal $ in it, and preg_replace is seeing it as a backreference. Here is what I am using: foreach($price_lists as $list)...
3
3460
by: Sebastian Araya | last post by:
Hello, I have a string like this: var1: value1...valueI var2: value1...valueJ ... varN: value1...valueK this is an example: breakfast: coffee eggs lunch: sandwich apple dinner: chicken...
6
2696
by: JDJones | last post by:
Just want to verify. I have a form and I want to parse any semi-colons out of the submitted info and replace with commas. Would this be the correct way to do it? $question1 = preg_replace(";",...
5
2104
by: paul brown | last post by:
howdy, I have some text: This is {search}Pam Grier{/search}. What I want is this: This is <a href="somepage.php?keyword=Pam Grier">Pam Grier</a>.
3
5305
by: Charles | last post by:
I'm new to this regular expression stuff. I'd like to use preg_replace to eliminate a known multi-line signature from the body of an E-mail. Say the body text is in $body, and the sig is this ...
22
2740
by: stoppal | last post by:
need to extract all text between the following strings, but not include the strings. "<!-- #BeginEditable "Title name" -->" "<p align="center">#### </p>" I am using preg_match(????, $s,...
5
498
by: julianmlp | last post by:
I'm fairly new to regex code, and I'm trying to find a way to replace any text after "///" (three slashes) and before a "\n" character. I've tried with: $filen = preg_replace("///./\n$", "",...
7
2019
by: monomaniac21 | last post by:
hi all using preg_replace how can i replace the letter i in a string with nothing (delete it) when it is the last letter or it is followed by an i? i have products that are listed in a db...
8
2349
by: erikcw | last post by:
Hi all, I'm trying to write a regex pattern to use in preg_replace. Basically I want to put around every line (\n) in this variable. However, I need to exclude lines that already have brackets...
3
1015
by: Silvertype | last post by:
Hi guys, I have these html tags: <input type="text" id="txtName" name="txtName" /> <textarea id="taHello" name="taHello">hello world</textarea> which I want to replace with the following...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7281
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
7334
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
7462
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...
0
5579
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1514
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
737
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
383
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.