Answers for "regex replace"

3

regex replace certain string

str = str.replace(/[^a-z0-9-]/g, '');

/* Everything between the indicates what your are looking for

    / is here to delimit your pattern so you have one to start and one to end
    [] indicates the pattern your are looking for on one specific character
    ^ indicates that you want every character NOT corresponding to what follows
    a-z matches any character between 'a' and 'z' included
    0-9 matches any digit between '0' and '9' included (meaning any digit)
    - the '-' character
    g at the end is a special parameter saying that you do not want you regex to stop on the first character matching your pattern but to continue on the whole string

Then your expression is delimited by / before and after. So here you say "every character not being a letter, a digit or a '-' will be removed from the string". */
Posted by: Guest on October-18-2020
31

javascript replace

var res = str.replace("find", "replace");
Posted by: Guest on October-21-2019
3

c# regex replace

Regex.Replace(
  "input string", @"[a-zA-Z]+", "replace string"
);
Posted by: Guest on May-21-2020
2

string replace javascript

let re = /apples/gi; 
let str = "Apples are round, and apples are juicy.";
let newstr = str.replace(re, "oranges"); 
console.log(newstr)

output:

"oranges are round, and oranges are juicy."
Posted by: Guest on November-23-2020
8

regex replace /

// replaces all / in a String with _
str = str.replace(/\//g,'_');
Posted by: Guest on May-29-2020
0

Replace string using regex

import re
line = re.sub(r"</?\[\d+>", "", line)
Posted by: Guest on September-06-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language