473,666 Members | 2,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RegExp for removing text between parenthesis

Hi,

I have a string like this:
GeboGebo Wiki 0.9.2 (Default branch)

I want to remove the words between the parenthesis. I tried this regexp:
/\([a-zA-Z0-9]\)/ but without success, what is wrong with it ?

Thank you,
--
Colossus

Cpsed, a Linux OpenGL 3D scene editor
http://cpsed.sourceforge.net/
Jul 17 '05 #1
5 7055
Colossus wrote:
I have a string like this:
GeboGebo Wiki 0.9.2 (Default branch)

I want to remove the words between the parenthesis. I tried this
regexp: /\([a-zA-Z0-9]\)/ but without success, what is wrong with it
?


You're looking for *exactly one* character a-z or 0-9.

RegExp /\([a-z0-9\ ]+\)/ might work a bit better. Though, it takes the
parenthesis with the contents, and I don't know if that's the wanted
behaviour (you said you wanted to remove the *text* between
parenthesis).

--
Markku Uttula

Jul 17 '05 #2
Markku Uttula wrote:
RegExp /\([a-z0-9\ ]+\)/ might work a bit better. Though, it takes the
parenthesis with the contents, and I don't know if that's the wanted
behaviour (you said you wanted to remove the *text* between parenthesis).


Thank you, i should also remove the parenthesis. How to do ?
--
Colossus

Cpsed, a Linux OpenGL 3D scene editor
http://cpsed.sourceforge.net/
Jul 17 '05 #3
Colossus wrote:
I have a string like this:
GeboGebo Wiki 0.9.2 (Default branch)

I want to remove the words between the parenthesis.
If your string is, as you say, like that, why not use the
string functions instead?

substr($subject ,0,strpos($subj ect,'('))
I tried this regexp:
/\([a-zA-Z0-9]\)/ but without success, what is wrong with it ?


Your character class doesn't allow spaces and only matches a
single character and the surrounding brackets.

`\([a-z ]+\)`i

--
Jock
Jul 17 '05 #4
John Dunlop wrote:
Your character class doesn't allow spaces and only matches a
single character and the surrounding brackets.
`\([a-z ]+\)`i


Thank you, it works ! I don't know php; can the substr be used as a
replacement of the regexp `\([a-z ]+\)`i ? Which is faster ?
--
Colossus

Cpsed, a Linux OpenGL 3D scene editor
http://cpsed.sourceforge.net/
Jul 17 '05 #5
Colossus wrote:
can the substr be used as a replacement of the regexp `\([a-z ]+\)`i ?
The regular expression matches letters and spaces and the
surrounding brackets, whereas the substr returns everything
up to the first '('. The equivalence of their output
depends on your subject string.
Which is faster ?


I don't know. Can you tell me?

--
Jock
Jul 17 '05 #6

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

Similar topics

3
9165
by: Jane Doe | last post by:
Hello, I need to browse a list of hyperlinks, each followed by an author, and remove the links only for certain authors. 1. I searched the archives on Google, but didn't find how to tell the RegExp object to be non-greedy as using the ? quantifier doesn't seem to work. --------- SAMPLE ----------------
4
24749
by: McKirahan | last post by:
How would I use a regular expression to remove all trailing Carriage Returns and Line Feeds (%0D%0A) from a textarea's value? Thanks in advance. Also, are they any great references for learning how to use Regular Expressions?
0
1813
by: Chris Croughton | last post by:
I'm trying to use the EXSLT regexp package from http://www.exslt.org/regexp/functions/match/index.html (specifically the match function) with the libxml xltproc (which supports EXSLT), but whatever I do gets errors. The examples use namespace regExp, but the supplied files use regexp, I've got it so that it at least doesn't complain about namespaces but it then complains that it can't find the match function. My stylesheet is:
6
1408
by: Christoph | last post by:
I'm trying to set up client side validation for a textarea form element to ensure that the data entered does not exceed 200 characters. I'm using the following code but it doesn't seem to be working correctly: if( this.value != '' ) { if( !( RegExp( '^{0,200}$' ).test( this.value ))) { alert( 'Information provided must not be more than 200 characters.' ); this.focus(); } }
7
3439
by: Csaba Gabor | last post by:
I need to come up with a function function regExpPos (text, re, parenNum) { ... } that will return the position within text of RegExp.$parenNum if there is a match, and -1 otherwise. For example: var re = /some(thing|or other)?.*(n(est)(?:ed)?.*(parens) )/ var text = "There were some nesting parens in the test"; alert (regExpPos (text, re, 3));
3
1862
by: Peter Michaux | last post by:
Hi, In the following string I would like to find the word that comes after "test" as long as test is not inside parenthesis. In this example the match would be "two". "the (test one) test two" I found some indication that Perl regexp can do this with some sort of recursive regexp. Can JavaScript regular expressions ensure that all
3
1557
by: Russell | last post by:
hey, I'm struggling trying to get the concepts of the regExp function down.... What i'm trying to achieve is to remove all white space from html formatted source code. I have the following regExp search string to remove all html source code but that is not what i require.. RegExp.Pattern = "\<.*?\>"
4
1200
by: eight02645999 | last post by:
hi suppose i have a string like test1?test2t-test3*test4*test5$test6#test7*test8 how can i construct the regexp to get test3*test4*test5 and test7*test8, ie, i want to match * and the words before and after? thanks
4
3900
by: Matt | last post by:
Hello all, I have just discovered (the long way) that using a RegExp object with the 'global' flag set produces inconsistent results when its test() method is executed. I realize that 'global' is not an appropriate modifier for the test() function - test() searches the entire string by default. However, I would expect it to degrade gracefully. Instead, I seem to be getting something as follows - using W3Schools handy page at :
0
8356
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
8869
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
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
8551
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
8639
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7386
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
5664
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
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1775
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.