www.webdeveloper.com
Results 1 to 2 of 2

Thread: Find Parentheses In A String

  1. #1
    Join Date
    Sep 2009
    Posts
    1

    Find Parentheses In A String

    Can someone tell me why this doesn't work and what I need to use instead?

    Code:
       <script type="text/javascript">
           var MyVar = "My variable (with parentheses)";
           var MatchPosition = search.MyVar(/\)/);
           alert(MatchPosition);     
        </script>
    Thanks

  2. #2
    Join Date
    Oct 2003
    Location
    Andover, UK
    Posts
    947
    If you want the match position, use indexOf(). This only looks up substrings, not regular expressions, but that should be fine in your case since you're only looking for brackets and thus have no need to use regular expressions.

    you could also do MyVar.match(/\)/) but that would return the match, not the position.

Thread Information

Users Browsing this Thread

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

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