regular expression meaning here

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pradeepjain
    Contributor
    • Jul 2007
    • 563

    regular expression meaning here

    hii guys, sorry this might seem to be a silly question
    what does /\b/g here means ,what is he trying to do with this code.
    Code:
        var matches = $(field).val().match(/\b/g);
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    usually a backspace or word boundary. guess it is testing an input field if there was something written in.

    Comment

    • pradeepjain
      Contributor
      • Jul 2007
      • 563

      #3
      it was used in a script for word count .

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        According to this regular expression reference:
        \b: matches at the position between a word character (anything matched by \w) and a non-word character (anything matched by [^\w] or \W) as well as at the start and/or end of the string if the first and/or last characters in the string are word characters.

        The /g applies the regular expression globally to what ever you are using (instead of stopping after the first occurrence that regex matches). For more information on global matching see the Advanced regular expression resource.

        -Frinny

        Comment

        Working...