www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] regex matches periods but not square brackets

  1. #1
    Join Date
    May 2005
    Posts
    242

    resolved [RESOLVED] regex matches periods but not square brackets

    Can't figure out why the pattern will match a period but not a square bracket.

    For example, it will match "See Jack run." but not "See [Jack] run.". Just ignores the brackets.

    Any ideas? Thx!

    Code:
    var title = note_title.value;
    
    // validate periods and brackets	
    var patt = '\\.\\[\\]';
    var mod = 'g';
    var dupe_patt = new RegExp(patt,mod);
    	
    if(title.match(dupe_patt)){
      console.log('no periods or brackets allowed in title');
      return false;
    }

  2. #2
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Your regex searches for the string ".[]" only.

    To find any of those characters, try:
    Code:
    var patt = '[\\.\\[\\]]';
    You don't need the g flag.

  3. #3
    Join Date
    May 2005
    Posts
    242
    ahhh, thx Logic Ali, worked perfectly!!

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