www.webdeveloper.com
Results 1 to 4 of 4

Thread: replace characters by regExp with exclude

Hybrid View

  1. #1
    Join Date
    Aug 2009
    Posts
    38

    replace characters by regExp with exclude

    How can I match first letters and also if the letter is precedded by period, comma or colon (even with no space between), but not if the letter is preceded by a quote or dubble quote.

    Lookbehind is not supported by JavaScript. (tried /\b(?<!\'|\")[\w]/g with syntax error). Any replacement method?

    Ex: abcd e'fgh hj"kl mno.p q:rst uv,wx
    The match should be a,e,h,m,p,q,q,r,u,w (excluding f,k)

  2. #2
    Join Date
    Feb 2006
    Posts
    2,926
    Code:
    String.prototype.firstLetters= function(){
        var m=this.match(/^[^a-zA-Z]*(([a-zA-Z])|[\. ,:]([a-zA-Z]))/g
        return m.slice(1);
    }
    Last edited by mrhoo; 09-03-2009 at 10:03 AM.

  3. #3
    Join Date
    Aug 2009
    Posts
    38
    Thx for reply.
    What if I want to replace these matched letters with space? Can I use string.replace on this?

  4. #4
    Join Date
    Aug 2009
    Posts
    38
    your pattern seems not to work. I pasted it on http://www.gskinner.com/RegExr/ and only the first letter of the string is matched.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles