reg = new RegExp("\\[.*?\\]", "g");
x = "[abc123.;.] this is more content";
console.log(x.replace(reg, "[contentreplacedwith]"));
If you use RegExp
constructor the there’s no need to pass /
delimiters and the options like g
for global are a second argument.
More Related Contents:
- How to do this mouse over effect in jquery?
- Total sum is NaN – Javascript
- Creating a JavaScript global array with static elements?
- Why is setState in reactjs Async instead of Sync?
- Updating a Nested Array with MongoDB
- Issue in returning data retrieved from DB queries called in the loop
- setImmediate vs. nextTick
- Passing environment-dependent variables in webpack
- How to get a URL parameter in Express?
- Is there a jQuery autogrow plugin for text fields?
- Finding all indexes of a specified character within a string
- Webkit-based blurry/distorted text post-animation via translate3d
- Skip arguments in a JavaScript function
- How to retrieve the element where a contextmenu has been executed
- How to create an array in JavaScript whose indexing starts at 1?
- programmatically changing webkit-transformation values in animation rules
- JavaScript, elegant way to check nested object properties for null/undefined [duplicate]
- Stop javascript Date function from changing timezone offset
- What are asynchronous functions in JavaScript? What is “async” and “await” in JavaScript?
- Fix the upstream dependency conflict installing NPM packages
- jQuery/JS, iOS 4 and $(document).height() problems
- Bizarre console.log behaviour in Chrome Developer Tools [duplicate]
- Selenium WebDriver wait till element is displayed
- Create XML in JavaScript
- Observe mutations on a target node that doesn’t exist yet
- hide div if clicked outside of it [duplicate]
- Why are JavaScript negative numbers not always true or false?
- Dynamically change Tweet Button “data-text” contents
- Why this regex is not working for german words?
- HTML5 Notification not working in Mobile Chrome