I need to replace all occurances of a certain character located between
two tags. I have included an example of what i have come up with so far,
but it doesn't work they way I want it to:
str = "some content<script type=\"text/javascript\">va r str =
'asdfasdfASDFAS DF';<\/script>";
str = str.replace(/(<script.*?>.*? )a(.*?<\/script>)/gim, "$1X$2");
alert(str);
In this example, i want all 'a' between the script tags to be replaced
by 'X', but only the first is replaced. How can I modify this to replace
*all* occurances of 'a'?
/MB 3 2573
MB wrote on 29 mrt 2007 in comp.lang.javas cript:
I need to replace all occurances of a certain character located between
two tags. I have included an example of what i have come up with so far,
but it doesn't work they way I want it to:
str = "some content<script type=\"text/javascript\">va r str =
'asdfasdfASDFAS DF';<\/script>";
str = str.replace(/(<script.*?>.*? )a(.*?<\/script>)/gim, "$1X$2");
alert(str);
In this example, i want all 'a' between the script tags to be replaced
by 'X', but only the first is replaced. How can I modify this to replace
*all* occurances of 'a'?
str = str.replace(/(<script.*?>)(. *)(?=<\/script>)/gi, function(x,y,z)
{return y+z.replace(/a/gi,'Z')})
[beware of line break. IE tested]
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
>I need to replace all occurances of a certain character located between
>two tags. I have included an example of what i have come up with so far, but it doesn't work they way I want it to:
str = "some content<script type=\"text/javascript\">va r str = 'asdfasdfASDFA SDF';<\/script>"; str = str.replace(/(<script.*?>.*? )a(.*?<\/script>)/gim, "$1X$2"); alert(str);
In this example, i want all 'a' between the script tags to be replaced by 'X', but only the first is replaced. How can I modify this to replace *all* occurances of 'a'?
str = str.replace(/(<script.*?>)(. *)(?=<\/script>)/gi, function(x,y,z)
{return y+z.replace(/a/gi,'Z')})
[beware of line break. IE tested]
Thanks. This works well, however only as long as the contents of 'str'
is just one line. It does not find any matches when I have several
lines. I tried adding the m-flag to the regular expressions, but that
didn't work. Can this be solved too?
/MB
MB wrote on 29 mrt 2007 in comp.lang.javas cript:
>>I need to replace all occurances of a certain character located between two tags. I have included an example of what i have come up with so far, but it doesn't work they way I want it to:
str = "some content<script type=\"text/javascript\">va r str = 'asdfasdfASDF ASDF';<\/script>"; str = str.replace(/(<script.*?>.*? )a(.*?<\/script>)/gim, "$1X$2"); alert(str);
In this example, i want all 'a' between the script tags to be replaced by 'X', but only the first is replaced. How can I modify this to replace *all* occurances of 'a'? str = str.replace(/(<script.*?>)(. *)(?=<\/script>)/gi, function(x,y,z ) {return y+z.replace(/a/gi,'Z')})
[beware of line break. IE tested]
Thanks. This works well, however only as long as the contents of 'str'
is just one line. It does not find any matches when I have several
lines. I tried adding the m-flag to the regular expressions, but that
didn't work. Can this be solved too?
str = str.replace(/\n/g,'\uffff').rep lace(/(<script.*?>)(. *)(?=
<\/script>)/gi, function(x,y,z) {return y+z.replace(/a/gi,'Z')}).repla ce(/
\uffff/g,'\n')
[beware of line breaks. IE tested]
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Patryk Konieczka |
last post by:
Hello
Here's the thing
I have a database edited by some company workers editing descriptions of
books in the sotre , unfortunately these workers do not have the habit of
inserting a space character after word-ending dot, this is why i use the
function:
function getCorrect($txt) {
$txt=str_replace(",",", ",$txt);
$txt=str_replace(".","....
|
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?
|
by: RobG |
last post by:
I'm messing with getPropertyValue (Mozilla et al) and currentStyle (IE)
and have a general function (slightly modified from one originally
posted by Steve van Dongen) for getting style properties:
function GetCurrentStyle( el, prop ) {
if ( window.getComputedStyle ) {
// Mozilla et al
return window.getComputedStyle(el,...
|
by: Dr Clue |
last post by:
I'm not really an expert with RegExp() , although I do use it.
The problem I have is that I want to strip comments out of a CSS
file using RegExp()
The reason is that I'm loading and parsing to simulate javscript
access to stylesheets in Opera. I thought I had it licked untill the
'/' characters in url('') tripped me up
Below is a test...
|
by: jiing24 |
last post by:
I try to use regexp to replace some html tags in DOM, but the result
seems some problems,
================================
<Script language="javascript" type="text/javascript">
var config = document.getElementById("rootconfig");
alert(config.innerHTML);
| |
by: deathtospam |
last post by:
I have a value, retrieved from a recordset, that contains any number of
hyperlinks to a number. For example:
<a href="123456">Hi</a<a href='334455'>Hola</a>
What I need to do is parse the string, identify any such valid
hyperlinks, look up each of those numbers in a database, and return a
string that looks something like this:
<a...
|
by: CJM |
last post by:
I'm trying to validate and input field that allows an integer or a single
'*' character using regular expressions, but I'm not getting the results I'm
expecting.
I'm trying to match against the pattern "*|", which I hoped would
translate to 'match against groups of the numbers (0-9) or against a single
*'. However, it's matching against...
|
by: HopfZ |
last post by:
I coudn't understand some behavior of RegExp.test function.
Example html code:
----------------
<html><head></head><body><script type="text/javascript">
var r = /^https?:\/\//g;
document.write( );
</script></body></html>
---------------------
|
by: runsun pan |
last post by:
Hi
I am wondering why I couldn't get what I want in the following 3 cases
of re:
(A)
var p=/(+-?+):(+)/g
p.exec("style='font-size:12'")
-- // expected
|
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...
|
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...
| |
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. ...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |