replace 2 « Regular Expression « Javascript Data Type Q&A

Home
Javascript Data Type Q&A
1.Array
2.Clojure
3.date
4.decimal
5.function
6.global
7.loop
8.math
9.number
10.object
11.Regular Expression
12.scope
13.String
14.Var
15.variable
Javascript Data Type Q&A » Regular Expression » replace 2 

1. regex replace just the last charater of a string    stackoverflow.com

Hi this should be an easy one and I couldn't find it anywhere. How do I replace just the last character of a string with a char from an array?

str1 = str1.replace(?????, ...

2. How to replace ASCII code (alt+207) in jvascript    stackoverflow.com

i have a string which contains square boxes(i found it's ascii code as alt+207)...how i can replace this with ' '(a single space). Thanks in advance.

3. IE Issue with Javascript Regex replacement    stackoverflow.com

r = r.replace(/<TR><TD><\/TD><\/TR>/gi, rider_html);
...does not work in IE but works in all other browsers. Any ideas or alternatives?

4. Replacing inner text with javascript and regular expression    stackoverflow.com

I am trying to do a modify a text which contain some special tags. I belive it should be possible by a single regular expression, but am stuck... What I want ...

5. JavaScript: how can I replace only Nth match in the string?    stackoverflow.com

So, I have a function which has two params: string and match index to replace and i need to replace only match with that index. How can i do that? Example:

replace('a_a_a_a_a', 1)
Result:
a__a_a_a
...

6. JavaScript replace string    stackoverflow.com

regexp: var s = document.getElementById("username").value; if s == "\ \ \ \"; var result = s.replace(/\/g,"") will be wrong? why that firebug error ? hope to the result is ...

7. JavaScript String replace - How do you use matched variables in the replacement string?    stackoverflow.com

How do you use the matched variables in the pattern in the replacement string?

var regexp = new RegExp('needle', 'ig');
str.replace(regexp, '<span class="marked">//1</span>')

8. Javascript regex replace function    stackoverflow.com

If I have the following string:

var str = "Test.aspx?ID=11&clicked=false+5+3";
str = str.replace(????????, 'true');
How can I replace the substring "false+5+3" with "true" using REGEX? Thanks in advance!!!

9. Replace all backslashes in a string with a pipe    stackoverflow.com

I have the string: \rnosapmdwq\salesforce\R3Q\OutputFiles\Archive I'm getting a unrecognized escape sequence when I try to send this to a .NET web service. I'm trying to replace all of the "\" with "|" to ...

10. Javascript string replace of dots (.) within filenames    stackoverflow.com

I'm trying to parse and amend some html (as a string) using javascript and in this html, there are references (like img src or css backgrounds) to filenames which contain full ...

11. Making bulk JavaScript replace more efficient    stackoverflow.com

I have some JavaScript which replaces smiley symbols with their corresponding images in my blog.
So symbols like :) or :( are replaced by proper <img> tags. Currently there are around ...

12. Replacing text using regular expressions in JavaScript    stackoverflow.com

I want to replace a simple text like: 1 day ago to Hace 1 dia I have tried the following code, but it does not work:

var texto = "1 day ago";
texto = texto.replace('/\d+(?=day ...

13. Javascript regex to replace /*    stackoverflow.com

I would like to replace a string. I have tried this, which I thought would work, but it doesn't

string = "/*"
string.replace(/\/(?=\*)/g,"replaced")
I tried escaping the asterisk and leaving it alone but both didn't ...

14. Help with JavaScript replace    stackoverflow.com

var isbn = '978-0393317558';
alert(isbn.replace(/^[^0-9]+/, '')); //this gives the same value
Why isn't that dash being replaced?

15. Error in Firefox while replace string using regexp in JavaScript    stackoverflow.com

try{    
  var hdnPassenger = $("#ctl00_ContentPlaceHolder1_hdnPassenger").val(); 
  var newTr = $("#hdnCtl").html(); 
  newTr = newTr.replace(/_ID/g, hdnPassenger); 
}
catch(ex){
  alert(ex);
}
Above code is working fine in the ...

16. Differences between replace(/[^a-z0-9]/gi, '') and replace(/[^a-zA-Z0-9]/g, '')    stackoverflow.com

Are there differences between these two?

replace(/[^a-z0-9]/gi, '');
replace(/[^a-zA-Z0-9]/g, '');
Also, are there any significant differences in time using one or another? edit: about the performance, I did some testing http://jsperf.com/myregexp-test

17. JavaScript RegEx: replace text in string between two "markers"    stackoverflow.com

I need this: Input

<div>some text [img]path_to_image.jpg[\img]</div>
<div>some more text</div>
<div> and some more and more text [img]path_to_image2.jpg[\img]</div>
Output
<div>some text <img src="path_to_image.jpg"></div>
<div>some more text</div>
<div>and some more and more text <img src="path_to_image2.jpg"></div>
This is my try and also ...

18. Javascript .replace() / regex with code as string    stackoverflow.com

I'm trying to "remove" (just replace it with "") the following String:

<script type="text/javascript">
document.createElement("img").src="http://www.google.com"
</script>
From the following String:
<SCRIPT LANGUAGE=JavaScript>
var PAswf = "_ADPATH_[%SWF File%]";
var advurl = "_ADCLICK_";
var PAadvurl = escape(advurl);
var PAwidth = "[%Width%]";
var PAheight ...

19. Javascript Regex for the String to replace    stackoverflow.com

I have a string like,

(Range:(>"A" OR Range:(>"B" OR Range:(>"AB")
I need to convert it like,
(Range:(>"A") OR Range:(>"B") OR Range:(>"AB"))
please help me out how to identify it with regex. Thanks in advance

20. string.replace(/""\n/g,"\"\""+ "\n") will this work?    stackoverflow.com

string.replace(/""\n/g,"\"\""+ "\n")
I am trying to parse a string and for using JSON parser. I need to replace the occurrence ""\n (quote, quote, newline) with \\"\\"\n (slash, quote, slash, quote, newline). I tried ...

21. javacript Replace() question    stackoverflow.com

Hey guys this is an easy one. I already am doing a replace for the commas in an textbox. How would I replace if there is an "$" and ...

22. Having trouble with javascript Replace()    stackoverflow.com

This code will replace the comma's no problem, but will leave the $ for some reason... Is it set up wrong? Trying to replace the $ also.

function doValidate() { 
  ...

23. javascript regular expression replacement doesnt work?    stackoverflow.com

why this regular expression replacement doesnt work?

var url = 'http://myweb.com/page/1/id/2'; 

newUrl = url.replace('/page\/[0-9]+/', 'page/2'); //it must become http://myweb.com/page/2/id/2

24. in javascript, cannot replace() using a sub-match    stackoverflow.com

wish to escape all occurrences of "." and ":" within square brackets

[ab:1.2:ef]='12.3' => [ab\:1\.2\:ef]='12.3'
tried various permutations on replace, eg,
str.replace( /(\[.*)(\.|:)(.*\])/g, '\1\\\2\3' );
but no joy.
Both answers correct and more. The first, a ...

25. Problems with creating regex in JavaScript    stackoverflow.com

I'm working on regex (regexes, actually) that will satisfy my needs. :) I need to replace given string (named title) and return slug:

  1. Replace one white-space with one underscore in places where are ...

26. JavaScript create regex programatically    stackoverflow.com

I know that I can create a javascript replace like this: str = str.replace(/mytarget/g, 'some value'); that will replace all the occurances of the literal mytarget. However, I have a big array of words/phrases ...

27. replacement of string using regular expression at Xth position intervals (javascript)    stackoverflow.com

I would very much appreciate some assistance from the community on replacing a string at xth position intervals, using javascript regex. For example, if the string length is 161 and ...

28. Should I regexp.test before I string.replace?    stackoverflow.com

When I want to replace some parts of a string, should I call replace directly like this?

var r1 = /"\+((:?[\w\.]+)(:?(:?\()(:?.*?)(:?\))|$){0,1})\+"/g;
arg = arg.replace(r1, function(outer, inner){
    return eval(inner);
});
Or test for ...

29. javascript string replace with another value    stackoverflow.com

Hello there ,

var s = "width:20px;height:25px;color:red;font-family:myfontfamily";
i have a string like this,now how can i change the values of width,height etc using javascript.there may be a \n after or before the ...

30. Prompt user to replace certain parts of text in a string    stackoverflow.com

I have a program that allows a user to type JavaScript in a textbox, and it executes in an HTML viewer or iframe. There is a drop down with options such ...

31. Javascript Regex (replace) Issue    stackoverflow.com

I am checking a collection and replacing all

<Localisation container="test">To translate</Localisation>
tags with text. The next codes does what I want:
var localisationRegex = new RegExp("(?:<|&lt;)(?:LocalisationKey|locale).+?(?:container|cont)=[\\\\]?(?:['\"]|(&quot;))(.+?)[\\\\]?(?:['\"]|(&quot;)).*?(?:>|&gt;)(.*?)(?:<|&lt;)/(?:LocalisationKey|locale)(?:>|&gt;)", "ig");

        ...

32. Replace by regexp in javascript    stackoverflow.com

I have the following string:

Are you sure you want to delete "%lg_name%" group?
And in Javascript I have the variable lg_name. How can I replace lg_name string to lg_name varible? This regex ...

33. Javascript replace does not replace    stackoverflow.com

The pattern in this code does not replace the parenthesis. I've also tried "/(|)/g".

var re = "/[^a-z]/g",
   txt = navsel.options[i].text.split(" ")[0], // here I get the text from a ...

34. Regex not working in Javascript with IE 7    stackoverflow.com

last_tag="abcde   x";
last_tag = last_tag.replace(/[\s]+x$/, '');
this is my problem: i have to remove an "x" at the end of my string. This piece of code is used in a plugin ...

35. Replacing usernames with links in Javascript with regular expressions    stackoverflow.com

I'm trying to match usernames within a string like:

"user: hi, has anyone seen user today user"
The cases to match:
  • substring is the first word trailing a space, in the middle surrounded by ...

36. jsfiddle fails on this regex?    stackoverflow.com

I'm prototyping some text processing to prep research data for coding, and I've got a javascript replace statement the bombs in jsFiddle and I cannot figure out why:

   mE[1] ...

37. Javascript- Use function for string.replace replacement text    stackoverflow.com

I'm attempting to replace url's in a string by calling a function that shortens the url's and then replaces the text. The shortening logic works perfectly, and I end up with ...

38. Regex based replace in js    stackoverflow.com

actually I want to replace a string except if it comes in a round bracket. For example:

JAVA is a nice language. (JAVA) has lots of features. JAVA is portable. (JAVA) ...

39. Regex: Not the beginning of a line?    stackoverflow.com

I have a string like this: ----------- 243f,33f---- Now I want to remove all the - chars except the first -, the , and the numbers. ...

40. JS replace with regular expression    stackoverflow.com

Need a regular expression. If I want to replace "abcdf" with "PPP" in

XabcdfX is xxxxxxx. <MabcdfM> has xxxxx. abcdf is xxxxxxx. <FabcdfF> zxabcdf abcdf.
then the expected output
XPPPX is ...

41. JavaScript regex replacement    stackoverflow.com

I have this string:

var s = '<span style="font-size:13px">20<div class="lblTitle"></div><span>';    
I'd like to replace the 20 to 40, I tried:
a.replace(/>(\d*)</, 40)  
But it will ...

42. Regex replace string which is not float    stackoverflow.com

I have a string, where I need to parse it as a float, but first I need to replace it, if it is not a number (an integer or a float), ...

45. Regex/replace()    codingforums.com

46. Replace portion of regex    codingforums.com

47. Why is RegExp replace() not working!?    forums.devshed.com

function pageJump( obj ) { var name = obj.name; var val = obj.options[obj.selectedIndex].value; var pattern = new RegExp(name+'=[0-9]+'); var tmp = location.href.split('?'); var href = tmp[0]; var query = tmp[1]; if ( query && query.match(pattern) ) { var replaceStr = name+'='+val; query.replace(pattern,replaceStr); alert(query+' : '+name+'='+val+' : '+pattern+' : '+replaceStr); } else if ( query && query != '' && query !== ...

48. REGEX Replace Problem    forums.devshed.com

49. Regex/string.replace problem    forums.devshed.com

hi, i have a problem with a call to the javascript string.replace() function. here's my code: function parseCodes_parseBold(s) { var re = /\[b\](.*)\[\/b\]/ig; return s.replace(re, "$1"); } all it does is convert a bbcode into html. so for example: [ b]bold text[/b] (no space obviously) would produce bold text (bold of course) my problem is that the regex matches the furthest ...

50. RegEx for replace last?    forums.devshed.com

51. regexp replace    forums.devshed.com

52. replace() regex    phpfreaks.com

var subject = 'bargain'; var foo = 'bar'; // works : use a variable and the pattern is the value of the variable var pattern = new RegExp(foo,"g"); str1 = subject.replace(pattern,''); alert(str1); // output : 'gain' // does not work : it looks for the literal string 'foo' str2 = subject.replace(/foo/g,''); alert(str2); // output : 'bargain'

53. Regex replace    sitepoint.com

54. RegExp match and replace problem    sitepoint.com

Hi All, I have this function that I'm using to preview a forum post. I'm trying to get it to remove the Break tags WITHIN the code blocks and not BETWEEN the code blocks and cant seem to find the right RegExp expression to do it. As you can see I'm converting the code blocks into a textarea input field much ...

55. Regexp replace    sitepoint.com

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.