regex - Regular Expressions:JavaScript -
What exactly would be the following statement:
a.replace (/ [^ \ w- ] / G, '-');
I have to find all the examples of '-' in between words and replace it with '-'.
In addition to this, if I get any examples
"Hi @ Raju, how do you do it?"
P> I want to secret the whole word like the word given below:
"Hi-Raju-what-what-what to do"
Terms:
- Change the white space with '-' 2. Replace special characters with '-'. 3. If we have more than one '-' result, replace the single with '-'.
- Remove '-' at the beginning and end of the string.
The following is a possible solution:
"Hi how do you do raju?". (+/- +/g, '-') .replace (/ ^ [\ s -] + | [\ s- (= \ s + | [@ \?] / G, '-').] + $ / G, '')) & Gt; Output: "hi-raju-u-to-do-do"
You can add any other 'special' character to the first code in
[] .
Comments
Post a Comment