Remove « 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 » Remove 

1. Regular expression to remove hostname and port from URL?    stackoverflow.com

I need to write some javascript to strip the hostname:port part from a url, meaning I want to extract the path part only. i.e. I want to write a function getPath(url) such ...

2. Regex in Javascript to remove links    stackoverflow.com

I'm really sorry if this has been answered before but I just can't seem to find the proper answer. I have a string in JS and it includes an href tag. ...

3. Beginner JavaScript RegEx Question: How to remove all characters from a string?    stackoverflow.com

How can I remove all characters from a string that are not letters using a JavaScript RegEx?

4. Will this remove all possible script tags?    stackoverflow.com

I am trying to make a regex that will just look for and remove script tags(its the only tag I wanted removed since I think it is the only one that ...

5. Regular expression in javascript to remove anything that is not: a-z 0-9 and hyphen    stackoverflow.com

Thanks in advance. I would like a regular expression that removes anything that is NOT alpha numeric and a hyphen. So allowed are A-Z 0-9 and -. Also, how could I apply that ...

6. Remove HTML Tags in Javascript with Regex    stackoverflow.com

I am trying to remove all the html tags out of a string in Javascript. Heres what I have... I can't figure out why its not working....any know what I am doing ...

7. Regex to remove javascript double slash (//) style comments    stackoverflow.com

I'm trying to do remove javascript comments via regex in C# and have become stuck. I want to remove any occurrences of double slash // style comments. My current regex is ...

8. regex to remove last line of block of text     stackoverflow.com

how do i remove the last line from a block of text in java script without using loops.(only using regex) eg., "The Internet is a global system of interconnected computer networks that use ...

9. Javascript - Removing part of url with regex    stackoverflow.com

I may have URLs like:

and what I would like to do is to remove part before /foo/bar/, with regex which will work if I have ...

10. Remove something in a match    stackoverflow.com

I have this regex. My problem is the two second lines of the code:

<% 
content = ""+Request.Form("completehtml")+"";
contentmatch = content;
contentmatch = content.match(/<div class="content">[\s\S]+?#-#/ig); 
htstring1 = contentmatch;
htstring2 = htstring1.replace(/#-#/ig, '');
 %>
I want to ...

11. Regex to remove all but file name from links    stackoverflow.com

I am trying to write a regexp that removes file paths from links and images.

href="path/path/file" to href="file"
href="/file" to href="file"
src="/path/file" to src="file"

and so on...
I thought that I had it working, but it ...

12. Regex remove everything thats outside { }    stackoverflow.com

Regex to remove everything outside the { } for example: before: |loader|1|2|3|4|5|6|7|8|9|{"data" : "some data" } after: {"data" : "some data" } with @Marcelo's regex this works but not if there are others {} inside ...

13. regex question for removal of javascript malware    stackoverflow.com

Been hit with some nasty javascript malware on my site. I know that each offending code block starts with the following:

<script language=javascript><!-- 
(function()
and ends with
</script>
I'd like to ...

14. Removing unnecessary parentheses in a regular expression    stackoverflow.com

Suppose I have (in a javascript regular expression)

((((A)B)C)D)
Of course that really reads
ABCD
Is there an algorithm to eliminate unnecessary parentheses in a string like that?

15. Regex to remove all functions from a js file [Textmate preferred]    stackoverflow.com

I'm working on a large and extremely messy javascript file, and I would like to remove all functions from the file, ultimately creating a version which contains only data. the code looks ...

16. Remove empty tags using RegEx    stackoverflow.com

I want to delete empty tags such as <label></label>, <font> </font> so that:

<label></label><form></form>
<p>This is <span style="color: red;">red</span> 
<i>italic</i>
</p>
will be cleaned as:
<p>This is <span style="color: red;">red</span> 
<i>italic</i>
</p>
I have this RegEx in javascript, ...

17. How can I remove the caret(^) from a string using a RegExp in Javascript?    stackoverflow.com

For some reason, I can't seem to find a good answer for this one. I have been trying to escape out the caret (\^), and to use the hex, octal, and other ...

18. regular expression to remove comment javascript    stackoverflow.com

I am using below regular expression to remove comments from string

<\!{1}\-{2}(.*?)\-{2}\s*>
This is working fine except for mult-iline string
var search = '<\!{1}\-{2}(.*?)\-{2}\s*>';

  var re = new RegExp(search, "gm");

  var ...

19. Regex remove line breaks    stackoverflow.com

I am hoping that someone can help me. I am not exactly sure how to use the following regex. I am using classic ASP with Javascript

completehtml = completehtml.replace(/\<\!-- start-code-remove --\>.*?\<\!-- start-code-end ...

20. Regexp: remove first and last slash    stackoverflow.com

I have these strings:

/banking/bonifici/italia
/banking/bonifici/italia/
and I would like to remove - with javascript - first slash and last slash if it's exists. I tried ^\/(.+)\/?$ but it doesn't work. Reading some post in stackoverflow ...

21. RegEx Question - Remove everything between : and ~    stackoverflow.com

I am having trouble getting a regex to work. This is the string.

"some text would be here and Blah St:39.74908:-104.99482:272~Turn right over here"
I need to remove the
:39.74908:-104.99482:272~
part of the ...

22. How do I use a regular expression to remove text in Javascript?    stackoverflow.com

Need to search a string and replace value="ANYTHING" with value="", basically blank out the value. Thanks.

23. need to modify this Regex to not remove a character    stackoverflow.com

I have the following regexp (/\?(.*?)\&/) which when I use it in the following javascript code it removes the "?" from the replacement result.

href=href.replace((/\?(.*?)\&/),"")
The beginning href value is this...
/ShoppingCart.asp?ProductCode=238HOSE&CouponCode=test
I get this ...

24. remove all
from a string
    stackoverflow.com

I have a string that i would like to remove all occurrences of <br> I tried this and it did not work.

    productName = productName.replace("<br>"," ");
However this worked but ...

25. Remove all characters after last - but only if after - has four characters    stackoverflow.com

I have a string which could contain several different values, among them are. EDITED for clarity: var test could equal FW21002-185 or FW21002-181-0001 or abcdefg or 245-453-654 or FW21002-181-00012 I would like ...

26. Removing dollar signs from prices    stackoverflow.com

I'm building a string of amounts but need to remove the dollar signs. I have this jQuery code:

  buildList($('.productPriceID > .productitemcell'), 'pricelist')
It's returning
pricelist=$15.00,$19.50,$29.50
I need to remove the dollar signs but ...

27. javascript regexp remove all special characters    stackoverflow.com

I would like one RegExp that will remove all special characters from a string. I am trying something like this but it doesn't work in IE7 (which is what the works ...

28. How to remove text between "()"    stackoverflow.com

Input: Dynamic Text (PDF 120 KB) Output: Dynamic Text

29. Javascript Regex: how to remove string before > and including >    stackoverflow.com

I have a string like so

item[3]>something>another>more[1]>here
hey>this>is>something>new
.
.
.
I would like to produce the following for each iteration indicated by each new line
item[3]>something>another>more[1]>here
something>another>more[1]>here
another>more[1]>here
more[1]>here
here
Another example:
hey>this>is>something>new
this>is>something>new
is>something>new
something>new
new
I would like a regex or some way to incrementally remove ...

30. Javascript regular expression to remove characters from the end of a string    stackoverflow.com

I have a couple strings like:

net_weight_(lbs)
net_height_(inches)
I need a regular expression that will remove the _(x) from the end of the string. So in my two examples, I would be left ...

31. Removing backslashes from strings in javascript    stackoverflow.com

I have a url in this format: http:\/\/example.example.ru\/u82651140\/audio\/song.mp3 How can I remove the extra "\"s from the string? I have tried string.replace("\","") but that does not seem to do anything. If you could ...

32. Remove HTML comments with Regex, in Javascript    stackoverflow.com

I've got some ugly HTML generated from Word, from which I want to strip all HTML comments. The HTML looks like this

<!--[if gte mso 9]><xml> <o:OfficeDocumentSettings> <o:RelyOnVML/> <o:AllowPNG/> </o:OfficeDocumentSettings> </xml><![endif]--><!--[if gte ...

33. Trying to remove trailing text    stackoverflow.com

I having the following code. I want to extract the last text (hello64) from it.

<span class="qnNum" id="qn">4</span><span>.</span> hello64 ?*
I used the code below but it removes all the integers
questionText = questionText.replace(/<span\b.*?>/ig, ...

34. Removing one character hash / pound symbol from the start    stackoverflow.com

I stumbled across this article which was talking about AJAX and jQuery and I reached this line

hash = hash.replace(/^.*#/, '');
where hash is in the form #page1,#page2 etc... Now what I ...

35. Javascript RegEx: remove all HTML but links    stackoverflow.com

Any way to easily remove all HTML from text but keep all links? I know how to strip all HTML tags, but can't figure out how to keep just links... Here's my ...

36. How to remove duplicate character at the end of a string in Regex    stackoverflow.com

Can anyone help me with the following regex

<script type="text/javascript">
        function quoteWords() {
            var ...

37. Remove \n using regular expression in javascript    stackoverflow.com

I have a javascript string contains html table like this:

  <div class="nobrtable"><table class="at"><TBODY><TR><td> FY

  </TD><td> Profit Margin

  </TD><td> Asset Turnover

   </TD><td> RoA

   </TD><td> Leverage ...

38. How to remove Bullets from the text using javascript regular expression    stackoverflow.com

I am just trying to remove bullets from the text. For example when i am copying bulleted text list from MS Word to any textbox it is showing along with bullet. ...

39. How to identify and Remove any type of Bullet in the Text    stackoverflow.com

I am copyig some data from the MS Word. That text may contain or May not contain Bullets in the copied text. But i need a Regular expression in javascript to ...

41. JS regex remove typecasts    stackoverflow.com

I'm trying to remove all type casts from a js file. The current (not-working) regex I have is:

/(?!new\s+&?!function\s+)\w+\((.+)\)/gi
Basically I want anything like Class(var) but not new Class(arg) or function Func(arg) Thanks!

42. Using sed to remove all console.log from javascript file    stackoverflow.com

i'm trying to remove all my console.log, console.dir etc from my js file before minifying it with yui (on osx). the regex i got for the console statements looks like this:

console.(log|debug|info|warn|error|assert|dir|dirxml|trace|group|groupEnd|time|timeEnd|profile|profileEnd|count)\((.*)\);?
and it ...

43. Removing all script tags from html with JS Regular Expression    stackoverflow.com

i want to strip script tags out of this html at pastebin

http://pastebin.com/mdxygM0a
I tried using the below regular expression
html.replace(/<script.*>.*<\/script>/ims, " ")
But it does not remove all ...

44. remove