How to replace *( in a string
My string is Mario *(cart) and I need to replace the *( in order to get Mario (cart). I don't want to replace just the asterisk, but the asterisk followed by an open parenthesis using global in a regex.
Here the code I'm trying to fix:
var str = 'Mario *(cart)';
str=str.replace(/\*\(/g,'(');
CORRECTION The regex works fine, but do not work when I leave the parenthesis without a value.
I made this code to answer at Creating dynamic formula
jsFiddle: https://jsfiddle.net/qpsh940m/
Answer
Following http://regexr.com/ your regex is fine.
Following javascript replace docs you are using correctly .replace
There is nothing wrong in your code, i tested it on the javascript console (chrome) and its worked right, here is the log:
var str = 'Mario *(cart)';
undefined
alert(str)
undefined
var str2 = str.replace(/\*\(/g,'(');
undefined
console.log(str2)
VM650:2 Mario (cart)
undefined
Where are you trying to implement it?
Its dont matter where you read it, if its right and complete.
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM