473,396 Members | 1,678 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.

RegExp help!!

Hi, all!! Need a hand with a regular expression... Let's say I have this
string:
"Now is 'the time' for all 'good men' to come to 'the aid' of their country"

I want to delete each occurrance of any string contained within the
apostrophes, including the apostrophes. So in the above example, the result
should be:
"Now is for all to come to of their country"

Tried several different expressions, but can't find one that works... Any
ideas?

Thanks!
Jack
Jul 20 '05 #1
2 1314
Hi!

Use this script, please:

var s = "Now is 'the time' for all 'good men' to come to 'the aid' of their
country"

s = s.replace(/\'.+?\'/g,'');

alert(s);
--
Sergey.
http://www.takereal.com/freelance/
"Jack Black" <ja*************@hotmail.com> wrote in message
news:3f********@127.0.0.1...
Hi, all!! Need a hand with a regular expression... Let's say I have this
string:
"Now is 'the time' for all 'good men' to come to 'the aid' of their country"
I want to delete each occurrance of any string contained within the
apostrophes, including the apostrophes. So in the above example, the result should be:
"Now is for all to come to of their country"

Tried several different expressions, but can't find one that works... Any
ideas?

Thanks!
Jack

Jul 20 '05 #2
Sergey I.Grachyov wrote:
var s = "Now is 'the time' for all 'good men' to come to 'the aid' of their
country"

s = s.replace(/\'.+?\'/g,'');

alert(s);


Unfortunately, this will not work prior to JavaScript 1.5 where non-greedy
modifiers were implemented at first. Therefore it will probably not work in
Internet Explorer prior to version 6.0 SP-1, Opera below version 7.0 (CMIIW)
and definitely not in Netscape prior to 6.0 (Mozilla prior to /5.0).

However, if you cannot make a RegExp non-greedy, you can still design it
not to match substrings containing specific characters, so

s = s.replace(/'[^']+'/g, '');

will be greedy but will only match what is between each pair of "'",
and not "'the time'...'the aid'". And it will most certainly be
compatible with other UAs than Mozilla/5.0.

BTW: "'" within RegExp literals need not to be escaped.
PointedEars

Jul 20 '05 #3

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

Similar topics

0
by: Simon | last post by:
Hi, I have a table with a column that contains many names, like "Ant Simon Lucy", if I was looking for one name in the string of names I would do... SELECT * from classroom where name LIKE...
2
by: Yang | last post by:
hi i have this function to verify a valid url: $regexp = "^(https?://)?((+:)?+@)?(({1,3}\.){3}{1,3}|(+\.)*({0,61})?\.{2,3})(:{1,4})?((/?)|(/+)+/?)$"; but it wont work with .info domains. can...
1
by: ric.castagna | last post by:
Greetings, all... I've got an issue that I'm trying to solve and RegExp looks to be my only avenue. Background: We are using a popular third party control for input into a textarea. By...
2
by: Tamas Nyilanszky | last post by:
hi, i need to filter (e.g.) the number 149, 1307 and 3100 from a line like this one: <td id=l2 title=149>1307/3100</td> so i will be able to split that string with reg.split() and receive...
5
by: Davros9 | last post by:
Trying to get Regular Expressions working....... ---------------- Public Function SepString(InField As String) As String ''seperates on space and comma Dim RE As New RegExp Dim Matches As...
5
by: otrWalter | last post by:
Note: $code is a single line of code that the previous segment of this method has located. I have this... preg_match('/\bnew wBug\s*\(\s*(.+)\s*\);/i', $code, $arrMatches); $results =...
7
by: cirfu | last post by:
pat = re.compile("(\w* *)*") this matches all sentences. if fed the string "are you crazy? i am" it will return "are you crazy". i want to find a in a big string a sentence containing Zlatan...
4
by: Andrew Poulos | last post by:
I have a string that looks like this "cmi.interactions.fred.id" I need to test that: - the first part of the string is "cmi.interactions." (case sensitive). - the last part of the string is...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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
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
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...
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.