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\">var str =
'asdfasdfASDFASDF';<\/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 2563
MB wrote on 29 mrt 2007 in comp.lang.javascript :
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\">var str =
'asdfasdfASDFASDF';<\/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\">var str = 'asdfasdfASDFASDF';<\/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.javascript :
>>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\">var str = 'asdfasdfASDFASDF';<\/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').replace(/(<script.*?>)(.*)(?=
<\/script>)/gi, function(x,y,z) {return y+z.replace(/a/gi,'Z')}).replace(/
\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...
|
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...
|
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:...
|
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...
|
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 =...
| |
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...
|
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...
|
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;...
|
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: 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...
|
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,...
| |
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...
|
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: 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,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
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...
|
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...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |