473,657 Members | 2,634 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Preg and why [^word) doesnt work?

Hi
I was trying to write a script to replace some text inside some tags.

Lets say I had <tag stuff=stuff><ta g stuff=otherstuf f><another>

I wanted it to find all the <tag and remove them.

So I tried to write it so that it would go forward until it reached
[<^another] came. But when I tried that it would respond to another as
single characters and not as the word.

How can I do this with regular expressions, matching up against words using
[^ ] ?

I know I can do what Im trying to do other ways, but when it didnt work with
[^ ], it got me thinking about how to do it that way. Because there might
come other times when I want to 'NOT' against a word, and there has to be a
way of doing this with Regular expressions?

Thanks for any help you can give me.


Jul 17 '05 #1
2 1540
Juggernaut wrote:
Hi
I was trying to write a script to replace some text inside some tags.

Lets say I had <tag stuff=stuff><ta g stuff=otherstuf f><another>

I wanted it to find all the <tag and remove them.

So I tried to write it so that it would go forward until it reached
[<^another] came. But when I tried that it would respond to another as
single characters and not as the word.

How can I do this with regular expressions, matching up against words using
[^ ] ?
You can't. [xyz] means the set of characters "x", "y" or "z". [^xyz]
means the complement of this set, i.e. every character that isn't "x",
"y", or "z". Using either in a regex means "match against any member of
the corresponding set".
I know I can do what Im trying to do other ways, but when it didnt work with
[^ ], it got me thinking about how to do it that way. Because there might
come other times when I want to 'NOT' against a word, and there has to be a
way of doing this with Regular expressions?


Matching "all the things that aren't '<another>'" doesn't make much
sense. For instance, 'uff><anot' isn't '<another>', and you don't want
that removed, etc...

However, read the section on assertions in the section on Pattern
Syntax in the PHP manual, and see if that helps.

Otherwise, do it a different way. e.g.

preg_replace('/<tag .*?>/', '', $str);

Which is just about the simplest way you can express this, I think.

--
Oli

Jul 17 '05 #2
What you need is a lookahead assertion. The syntax if I remember
correctly is (?=<another).

Jul 17 '05 #3

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

Similar topics

1
2527
by: Station Media | last post by:
Hi, here my problem, i use stored procedure in ACCESS database(latest version), and i would like to use this procedure but it doesnt work, do you know why ? Procedure: PARAMETERS MyField Text ( 255 ); SELECT DISTINCT MyField AS Result FROM tb_Client;
3
7210
by: Clouds | last post by:
Hi ! How do I add the dynamic event handler for a dropdownlist present in the itemtemplate of a datalist !! I am doing it in the itemdatabound event of the datalist but it doesnt work... I am also setting the autopostback property to true for the dropdown list and it works but the handler doesnt get invoked at runtime... I have to do it in itemdatabound becaz whether to add the handler or not is driven based on the information which i...
2
1374
by: BSGY | last post by:
Hello app.Documents.Open("TEMPLATE.DOC", False, False, False, "", "", False, "", "") doesnt work on server. But it is working in my computer. What is the problem, what can i do ?
0
1632
by: Juna | last post by:
I have been working in vs2003, but now started to work in vs2005 but the problem, I have simple web application not website, which work i mean open in browser when we press F5 or run the application by pressing run button. but it doesnt work when we type the path directly in the browser's address bar eg. http://localhost/testapplicationdefault.aspx error it gives is "COULD NOT LOAD testapplication._default". IN default.aspx. While in...
1
2071
Digital Don
by: Digital Don | last post by:
I am writing a program for Peg solitaire... To check for no repetition of previous states I use a Set for storage of Board states.. The pronblem is when I declare the set as type char i.e. set <char> open it doesnt take any char values into it and says cannot convert char to const char... I wonder why is it converting char to const char when I have declared that it shud be of type char...It doesnt work with int either,.. Please help...
3
2967
by: jx2 | last post by:
hi guys i would appriciate your coments on this code - when i ran it for the very first time it doesnt see @last = LAST_INSERT_ID() but when i ran it next time it read it properly i need to know it imiedietely after i insert value into session1... is there any other way to do it? insert into 2 tables at the same time ...? if(!($sessid)){ session_register('sessid'); mysql_query("insert into session1 set sessid=null,
1
1588
by: Dany13 | last post by:
hi all. i using some text box for input value and some localvarible for passing this data to dataset . give instance for correct row of dataset and data in data table . use one gird view for showing curent data in dataset . in end i am calling update metod to insert data in sql database but this metod doesnt work correctly. at all doesnt work. but givenot any error . fill data from my database (work propebly) ...
20
2844
by: Hush | last post by:
Hi, The following code works fine in IE7 but FF returns with an error: Access denied to achieve the property Element.firstChild. In this line: nodes = xmlDoc.documentElement.childNodes; My code:
0
8319
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8739
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8512
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7347
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4171
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2739
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 we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.