SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Regex issues...

  1. #1
    SitePoint Wizard Wolf_22's Avatar
    Join Date
    Jul 2005
    Posts
    1,714
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regex issues...

    I have the following truncation expression and it's replacing everything when tripped--even anchor code.
    Code:
    trunc = trunc.replace(/\w+$/, '');
    What can I do to make it ignore the code that's used for anchor tags?

  2. #2
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    I'm not absolutely sure what you are asking for
    but I'll have a try

    Code JavaScript:
    var trunc = 'fffff#?ffffffff';
    trunc = trunc.replace(/[a-z#]+$/, '');
    // trunc == fffff#?


    I hope this can help.
    Bye.

  3. #3
    Under Construction silver trophybronze trophy AussieJohn's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    776
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    as per the MDC Regex documentation:
    -----------
    \w
    Matches any alphanumeric character from the basic Latin alphabet, including the underscore. Equivalent to [A-Za-z0-9_].

    For example, /\w/ matches 'a' in "apple," '5' in "$5.28," and '3' in "3D."
    -----------

    What is it you're trying to do? Truncate white space from the end of a string?

    If so, you'll probably want to use \s instead.
    var details = {
    . . web: "afterlight.com.au",
    . . photos: "jvdl.id.au",
    . . psa: "usethelatestversion.com"
    }


Bookmarks

Posting Permissions

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