I'm trying to write a regex function that will identify and replace a single instance of a match within a string without affecting the other instances. For example, I have ... |
This is a simple one. I want to replace a sub-string with another sub-string on client-side using Javascript.
Original string is 'original READ ONLY'
I want to replace the 'READ ONLY' with 'READ ... |
Do any of the existing JavaScript frameworks have a non-regex replace() function,
or has this already been posted on the web somewhere as a one-off function?
For example I want to replace "@!#$123=%" ... |
I'm trying to come up with a regular expression which will wrap all occurences of JJDnnnnnnnnnnnnnnnn within a string with an anchor pointing to an url which contains the matched string ... |
Hi guys
I have a string that looks something like the following 'test:1;hello:five;just:23'. With this string I need to be able to do the following.
....
var test = MergeTokens('test:1;hello:five;just:23', 'yes:23;test:567');
...
The end result ... |
Friends,
I'm new to both Javascript and Regular Expressions and hope you can help!
Within a Javascript function I need to check to see if a comma(,) appears 1 or more ... |
I am trying to wrap my head around using regular expressions and replace() with JavaScript, but have not yet been successful
Suppose I have a string containing this:
<img alt="a picture of ..." ...
|
|
Is there an easy way to change the case of a matched string with javascript?
Example
String : <li>something</li>
Regex : /<([\w]+)[^>]*>.*?<\/\1>/
And what I'd like to do is replace the match $1 to ... |
Given this function:
function Repeater(template) {
var repeater = {
markup: template,
replace: function(pattern, value) ...
|
I have an array of objects that have 2 properties: Key and Value. I have a block of text with placeholders that correspond to the object Keys. I want ... |
I have the following code, which works, but I need to inject some different stuff into the regular expression object (regex2) at runtime. However, text.replace does not seem to like a ... |
I'm trying to replace all the occurrences of a variable in a string using javascript.
This is not working.:
var id = "__1";
var re = new RegExp('/' + id + '/g');
var newHtml ...
|
Using JQuery, I'm extracting the value from what is essentially a query box for some data in a MySQL database. Knowing that most users will use an '*' (asterisk) as a ... |
var src = "http://blah.com/SOMETHING.jpg";
src.replace(/.*([A-Z])\.jpg$/g, "X");
at this point, shouldn't src be:
http://blah.com/SOMETHINX.jpg
If I use match() with the same regular expression, it says it matched. Regex Coach also shows a ... |
Hi
I have following HTML code:
Its look like
<html>
<head>
</head>
<style id="styletag">
.class3{
}
.sec2{
}
.this3{
}
</style>
<body>
<div class="class1 class2 class3">content</div>
<div class="sec1 sec2 sec3">content2</div>
<div class="this1 this2 this3">content2</div>
</body>
</html>
I am having the values class3, sec2 and this3 in array.
I want to ... |
Currently I have a basic regex in javascript for replacing all whitespace in a string with a semi colon. Some of the characters within the string contain quotes. Ideally I would ... |
This is for an autocomplete plugin that needs to accept data as an array of arrays and convert it using a format string (or regex). The format string could be any ... |
Does the JavaScript regex standard support forcing case when doing a search/replace?
I am generally aware of the \u etc. options for forcing the case of a capture group in the replacement ... |
Consider:
<%
content = ""+Request.Form("completehtml")+"";
contentmatch = content;
...
|
Hey there, I'm trying to replace a
<blockquote>...</blockquote>
with
>> ...
This is my Code:
var testhtml = 'sdkjhfbs <blockquote>skldfjsfkjghbs\n sdjkfhb ksdbhv isl\n kdjbhdfgkj bs</blockquote>kdjfgnkdfj';
alert(blockquoteConvert(testhtml));
function blockquoteConvert(html) {
return '>>' + html.
...
|
I have a string of tags delimited by semicolons:
"red; yellow; blue; green; purple"
I would like to strip out all the tags that do not match a substring (case-insensitive.)
For example, ... |
I have the following replace function
myString.replace(/\s\w(?=\s)/,"$1\xA0");
The aim is to take single-letter words (e.g. prepositions) and add a non-breaking space after them, instead of standard space.
However the above $1 variable doesn't work ... |
I know that I can pass a string as the second parameter to the JavaScript string object's replace method. In this case I can use $` and $' to reference the ... |
I have a variable that I'm using to build a JavaScript function call, and JavaScript's .replace() to surround the line of text with a span and onclick event. The .replace() ... |
I'm trying to work out what regular expression I would need to change this string
html = '<img style="width: 311px; height: 376px;" alt="test" src="/img/1268749322.jpg" />';
to this
html = '<img width="311" height="376" alt="test" src="/img/1268749322.jpg" ...
|
Ok so if I have this pattern:
ab&bc&cd&de&ef
And I need to replace all the ampersands except for the first one with commas so it ends up looking like this:
ab&bc,cd,de,ef
Its probably very simple ... |
A particular regular expression is bugging me right now. I simply want to replace the range=100 in a string like
var string = '...commonstringblabla<b>&range=100&</b>stringandsoon...';
with
...commonstringblabla<b>&range=400&</b>stringandsoon...
I successfully matched the "range=100"-part with
alert( ... |
How can I apply multiple regexs to a single string?
For instance, a user inputs the following into a text area:
red bird
blue cat
black dog
and I want to replace each carriage return with ... |
What I need to implement is to
find patterns in a string , store matches replace the matches with unique tokens so that later on the token could be replaced by ... |
I have the following:
[list]
[*] test
[*] test
[*] test
[/list]
and I would like to create a regular expression that turns that into:
<ul>
<li>test</li>
<li>test</li>
<li>test</li>
</ul>
I know regex enough to replace simple tags, but in this case I ... |
I'm writing a script to add extra smileys to the Gmail chat.
Its working partially, i'm stuck with the innerHTML.replace method @line 33
If you see, the regex in the replace ... |
I'd like to use Javascript to replace all instances of \u009 in a string
This doesn't seem to be working: .replace(/\u0009/g,'');
Do I need to escape something?
|
<html>
<body>
http://domainname.com/abc/xyz.zip
http://domainname2.com/abc/xyz.zip
</body>
</html>
I want replace with link and out put like
<html>
...
|
I'm having some troubles getting regex to replace all occurances of a string within a string.
**What to replace:**
href="/newsroom
**Replace with this:**
href="http://intranet/newsroom
This isn't working:
str.replace(/href="/newsroom/g, 'href="http://intranet/newsroom"');
Any ideas?
EDIT
My code:
str = '<A href="/newsroom/some_image.jpg">photo</A>';
str = str.replace('/href="/newsroom/g', 'href="http://intranet/newsroom"');
document.write(str);
Thanks,
Tegan
... |
I'd like to use javascript to search a string and automatically insert a closing tag before every occurrence of an opening tag. Here is the test code I've come up ... |
I have html code as a string variable
like a = "<span> Spain will win ....... </span>"
and I want to heightlight "spa" in the String.
I have to use RegExp, How should I ... |
var textTitle = "this is a test"
var result = textTitle.replace(' ', '%20');
But the replace functions stops at the first instance of the " " and I get the
Result : "this%20is ... |
I'm reading Sitepoints 2007 book "Simply Javascript" and I encountered some code I just can't understand.
It's the following code:
Core.removeClass = function(target, theClass)
{
var pattern = new RegExp("(^| )" ...
|
I have below test cases as input:
[This is my test] [This is my test] My name is xyz.
Want Expected output as :
[This is my test] My name is xyz.
. ... |
Hi
I have text inside "textarea" and I was trying to remove the text between: <textarea></textarea> using replace function with some regex. here is what I did so far:
x = '<TEXTAREA style="DISPLAY: ...
|
how to replace multiple occurrences of and <br> at start of the string with javascript regex?
|
I have a malformed URL like this: http://www.abc.com/?abc&?as&?blah
Now, I want to match (and eliminate) all "?" in the URL except the first one to make the URL clean. ... |
I have <li> elements in my document such as:
<li id="123" onMouseOver="foo();">Lorem Ipsum ...
I would like to remove the attributes and get the string <li>Lorem Ipsum .... In order to do that, ... |
Using JavaScript's replace and regex, how do I replace numbers 0-9 with the letters a-j ?
example mapping: 0 = a, 1 = b, 2 = c, 3 = d, 4 = ... |
I am hoping that someone maybe able to help me. I need to create a regex that will remove all duplicates from a input file - I am creating a ftp.exe ... |
var text = "'Hello'World'''";
how to replace all ' and Hello and World to '
result = "'''''''"
|
I want to replace all the occurrences of a string that doesn't start with "<pre>" and doesn't end in "</pre>".
So let's say I wanted to find new-line characters and replace them ... |
I'm highlighting instances of a search string within a set of text. I want to preserve the case of the original text while replacing a case-insensitive match of the query. Here's ... |
I need a javascript regex replace function to turn
<font anything_possible><span anything_different_possible></span>
into
<span anything_different_possible></span><font anything_possible>
I tried many combinations but failed. Any help appreciated.
|
I seem to be getting conflicting advice in the books I read on this functionality.
I'm wondering if someone could clarify.
For example Nicholas Zakas states the function argument has a signature of ... |
Hei all
I have this code
function prototype( str , id )
{
var ret = str;
ret = ret.replace( /ΓΈ/g, 'oe' );
ret = ...
|
The following replacement
"index.html".replace('\.html$', '_fr.html');
returns "index.html", indicating that the first argument didn't match anything. However, if I remove the "$"
"index.html".replace('\.html', '_fr.html');
then the first argument matches and "index_fr.html" is returned.
Returning to the first ... |
I have a regular expression, say /url.com\/([A-Za-z]+)\.html/, and I would like to replace it with new string $1: f($1), that is, with a constant string with two interpolations, the captured string ... |
I want to replace all {0} on a string with x. It should not match {{0}}.
How can I do it?
|
I am boggled by regex's I think I'm dyslexic when it comes to these horrible bits of code.. anyway, there must be an easier way to do this- (ie. list a ... |
I want to make replacements like this:
var txt = "Some text containing $_variable1 and with $_variable2 inside of it as well.";
var rx = /(\$_[a-z]+)/g
var $_variable1 = "A CAT";
var $_variable2 = "A ...
|
I want to write a regexp for balanced braces constructs like
{...}, {... {..}...} and {...{..{..}...}..{..}...} where ... means any text, which has no '{' or '}' chars
If I do this:
... |
I have a string (coming from ASP.NET) which contains one or more placeholders. In .NET I'm using the string.Format() method to replace the placeholders with actual values:
var str = "aaa {0} ...
|
Ok, I'm actually trying to replace text.
Basically, I am needing to replace all instances of this: | with a blank string ''
However, this isn't working:
langName = langName.replace(/|/g, '');
Also, would be ... |
I am trying to remove multiple spaces by using below codes,its removing   also,
but its not working for character N B S P.....
replace(SPACE, " ").replace(/^[\s\t\n\ \;]+|[\s\t\n\ \;]+$/g, '');
|
i need this in php to javascript.
echo preg_replace('/(\S)+\?/', '', 'http://example.com/?test=1');
THX
BTW: I tried
alert('http://example.com/?test=1'.replace('/(\S)+\?/g', ''));
but no happens.
|
i want to assign src attribute to alt attribute with removing extension .png and removing src attribute.
string1='<img src="a.png"> hi '
to :
string2='<img alt="a"> hi '
how to do this?
what is code?
|
I am refering to code from Case insensitive string replacement in JavaScript?:
RegExp.escape = function(str)
{
var specials = new RegExp("[.*+?|()\\[\\]{}\\\\]", "g"); // .*+?|()[]{}\
return str.replace(specials, "\\$&");
}
What does \\$& ... |
When I have something like this:
var str = "0123";
var i = 0;
str.replace(/(\d)/g,function(s){i++;return s;}('$1'));
alert(i);
Why does "i" equal 1 and not 4?
Also, is it possible to pass the real value of $1 ... |
I have this string inside a variable:
var s = 'I have _this_ string inside a variable';
and I need a regular epxression which would produce this result:
'I have <code>this</code> string ...
|
I've got a string which contains q="AWORD" and I want to replace q="AWORD" with q="THEWORD". However, I don't know what AWORD is.. is it possible to combine a string and a ... |
my string is like this
coder<coder@gmail.com>
i want coder@gmail.com back
any help will be appreciated!
|
Not sure why but i can't seem to replace a seemingly simple placeholder.
My approach
var content = 'This is my multi line content with a few {PLACEHOLDER} and so on';
content.replace(/{PLACEHOLDER}/, 'something');
console.log(content); // ...
|
I have a start and end marker in html, I would like to replace the html between these markers with some other html. The expression below doesnt seem to work...
var myRegExp ...
|
Is there a library for replacing using functions as argument
when I call this function
"foo[10]bar[20]baz".replacef(/\[([0-9]*)\]/g, function(a) {
return '[' + (ParseInt(a)*10) + ']';
});
it should return
"foo[20]bar[30]baz";
and when I call ... |
I got some html formatted in the following way:
[Title|<a class="external" href="http://test.com">http://test.com</a>]
From these texts I'd like to create links using "Title" as the text and "http://test.com" as link. How can I best ... |
The replace function returns the new string with the replaces, but if there weren't any words to replace, then the original string is returned. Is there a way to know whether ... |
I'm working on a JavaScript syntax highlighter, that I need for a project I'm starting later.
I have an expression called keywords.
var keywords = /break|case|catch|default|delete|do|else|false|for|function|if|in|instanceof|new|null|prototype|return|switch|throw|this|true|try|typeof|var|while|with/g
I then run script.replace(keywords, "<keyword>" + /* I ... |
I found this code on another question, but am not sure how to use it:
var text = document.getElementById("text").innerHTML;
text = text.replace(/"z"/g,
... |
I need to replace a button using a Regex in JavaScript and was wondering how to do this. I know how to grab the src of the button, but I need ... |
Can someone show me how to do the following in JavaScript? I know how to grab the src of the image, I just want to be able to replace the filename ... |
I am working with javascript and classic asp, I am hoping someone can help me with this regex.
I need to replace
" (quotes)
between apostrophe's with a regex.
I were thinking ... |
I am trying to highlight the word that has been passed in using regex & css. But something seems to have gone wrong. can anyone please help me? $1 doesn't seem ... |
I'm using REGEX and js replace to dynamically populate a variable in a href. The following code works the first time it is used on the page, but if a different ... |
I have following string:
text = '20 as a % of 50'
I need to replace it using a regular expression, the result should be:
'20 / 50 * 100'
How ... |
I have a langauge dropdown, and a javascript function which changes the page to the corresponding language selected. I need help on my regex replace:
For example, I would like this URL ... |
Greetings.
I have a function which watches the content of "price" field and updates the string in "cart" field. In "cart" field, string between | characters gets replaced with whatever is typed ... |
I am trying to replace some text after an underscore in a filename.
Example filename: FileName_true.png. I need to change it to FileName_false.png.
Basically, i have an image that i want to change ... |
I'm using Javascript to add <br /> in between every letter of text in a tag. Code is as follows:
$(this).html($(this).text().replace(/(.{1})/g, "$1<br />"));
It's adding several extra <br /> tags to the beginning ... |
I'm trying to replace any <br /> tags that appear AFTER a </h2> tag. This is what I have so far:
Text = Text.replace(new RegExp("</h2>(\<br \/\>.+)(.+?)", "g"), '</h2>$2');
It doesn't seem to ... |
Let's say I have text (not html), that I'm pulling from a textarea. It looks like:
ALTER LOGIN [user1] DISABLE
GO
~~~~~~~~~~~~~ important stuff to keep ~~~~~~~~~~~~~~~
~~~~~~~~~~~~~ important stuff to keep ...
|
Given only the email address, I'm trying to remove the email, corresponding person's name and the following comma (if exist) from the string regardless where in the string the email appears.
var ...
|
Code:
var csMasterPrefix = 'CS_',
cpMasterPrefix = 'CP_',
csContentPrefix = 'CSContent_',
cpContentPrefix = 'CPContent_';
/* ... */
$this.attr("id")
.replace(csMasterPrefix,'')
...
|
I'm trying to patch the Drupal Panels module to fix this nasty issue, which makes the AJAX errorhandler completely unreadable. The error handler has this:
// Replace all < and ...
|
I want to remove this from a url string
http://.....?page=1
I know this doesn't work, but I was wondering how you would do this properly.
document.URL.replace("?page=[0-9]", "")
Thanks
|
how to replace ( /" or /') to ( " or ') from the string in javascript. I am referring the content inside the braces. Could anyone give me regular expression ... |
How can you replace all occurrences found in a string?
If you want to replace all the newline characters (\n) in a string..
This will only replace the first occurrence of newline
str.replace(/\\n/, '<br ...
|
I have a Regex which replaces all non-alphanumeric characters with a hyphen.
slugName = $(this).val().replace(/[^a-z0-9]/gi, '-');
This works as it should, however since this is generated from user input, I may end ... |
Not sure where I am doing wrong. I have a string such as Test (123x) and I am trying to find the (123x) and replace it with nothing:
Here is my ... |
I can have a string that looks like this as an example:
sometext<a title="Wink"><img src="http:\\www.seemstatic.com\images\transparent.png" class="emoWink"></a>somemore text<a title="Wink"><img src="http:\\www.seemstatic.com\images\transparent.png" class="emoWink"></a>endof text...
I have the following Javascript that matches the above string, and replaces ... |
I'm continuing work on a search term suggestion tool using Jquery UI. I am now working on displaying the results with the search term pattern in bold. I have ... |
I have the following text in a file called build.xml:
component.rollup=true
component.rollup.modules.buildfiles=io-base.xml, io-form.xml, io-xdr.xml
component.rollup_dir=/base
I want it to add one file in it so it will become:
component.rollup=true
component.rollup.modules.buildfiles=io-base.xml, io-form.xml, io-xdr.xml, io-extended.xml
component.rollup_dir=/base
How can I do that ... |
The following attempt to replace whitespaces with hyphens works in Firefox but not IE:
metatext = metatext.replace(/[\s]/g,"-");
Neither do the following alternative attempts work in IE:
metatext = metatext.replace(/[\s+]/g,"-");
metatext = metatext.replace(/[ ]/g,"-");
Insights appreciated.
|
I am doing some logic to a string and everything workes fine in Firefox. Found error in IE but confused to fix it.
var txt=[], regg=/<\/?[^>]+>/gi, ost=str.replace(regg,'').substr(0,l), g=j=0;
var match = null;
while(match = ...
|
I have the follow I am trying to replace
"'234324234234234236548723adf83287942'"
Basically I am trying to use
var specialId = otherSpecialId[0].trim().replace(/^[']*$/,'');
To try and get
"234324234234234236548723adf83287942"
But I can't seem to crack it ? How do I remove ... |