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:

  1. Change the white space with '-' 2. Replace special characters with '-'. 3. If we have more than one '-' result, replace the single with '-'.
  2. 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

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -