473,769 Members | 4,985 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Remove everything between square brackets.

5 New Member
Hello

I'm trying to remove square brackets and everything between them from a string, using regular expressions
I know how to use preg_replace, and know the basics of regex, but can't success.
Can anyone please give me a regex for it?

Thanks in advance!
Edan
Dec 15 '07 #1
2 4610
Markus
6,050 Recognized Expert Expert
Post what code you have now and we can improve on that.
Dec 15 '07 #2
Edan
5 New Member
Okay --

Expand|Select|Wrap|Line Numbers
  1. $string = '1 [fsdfsdfsdf] 2 [fsdfsd] 3';
  2. $string  = preg_replace('/\[(.*)\]/', '', $string); 
  3. echo $string;
  4.  
Outputs '1 3' for some reason (while it should output 1 2 3).

Unfortunately, I'm not very good with regular expressions and I can't work this out.
Dec 16 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
6435
by: Veverita | last post by:
Hi there I'm hoping that someone can help me with a question I have about javascript syntax. I got an html page that uploads an image and some text field to a database. What I'd like to do is modify the content of one of the textfields prior to it being submitted to the database. Specifically, I need to
9
5576
by: Christine | last post by:
It has come to my attention that sometimes, when I open a Query in SQL View, the SQL that I see is not exactly the same as the SQL in the Query's Querydef. The difference I see (only occasionally) has to do with square brackets and dot on some tblName.FieldName portions of the query. The following routine demonstrates how I see the QueryDef's SQL: Sub DbgQuery(sQryName As String) '' Prints the SQL for the given query to the Debug Window...
5
10614
by: Daniel Klein | last post by:
In the MSDN documentation I see examples like: Dim val As () = {"a", "b", "c"} If I remove the brackets, ie, Dim val As String(), it seems to work the same way. What are the brackets for? And what is the difference when they are used/omitted? I can find no mention of this anywhere in the MSDN docs.
8
8570
by: Paul | last post by:
Hi, My VB is very rusty I'm afraid! What would be the most efficient way to remove the following ASCII characters from a string? à è ì ò ù À È Ì Ò Ù á é í ó ú ý Á É Í Ó Ú Ý â ê î ô û Â Ê Î Ô Û ã ñ õ Ã Ñ Õ ä ë ï ö ü ÿ Ä Ë Ï Ö Ü Y o O æ Æ
3
2948
by: balakrishnan.dinesh | last post by:
Hi frnds, Im having a problem in searching out a particular substring in a string. Here the code: --------------------- <html> <script> var tmpString=" ";
37
19206
by: bahoo | last post by:
Hi, I have a list like and as output I want If I myList.remove('0024') then only the first instance of '0024' is removed.
3
5367
by: Grande News | last post by:
Hi, I've got some PHP code that looks like this $cura= ord($data{$pnum*2}); $curb = ord($data{$pnum*2+1}); Notice the curly braces -- does using them make any difference, or will square brackets do the same thing? Thanks B
0
760
Shashi Sadasivan
by: Shashi Sadasivan | last post by:
A very noob type question... But what the properties defined on the method in square brackets called? Ive been using a lot of methods on top of them, Havent done much otherwise, So am planning to jump into it. But need a head start at what are they called !!! thanks !
8
11665
hsriat
by: hsriat | last post by:
I need to compare a string with a regular expression that contains square brackets in itself. eg. If I test() a regExp ("^]", "i") with string "]Bold Text]", it should return true. But its returning false due to square brackets. How can I solve this? var txt = "]Page starts]"; function matchTag(start) { var regStart = new RegExp("^", "i"); if (regStart.test(txt)) alert ('Matching');
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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
10045
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...
0
8870
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
6673
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
5298
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...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
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
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.