SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2011
    Location
    Bellingham, WA
    Posts
    450
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Regex Match with javascript

    Hello!

    I'm trying to do a javascript match for links that start with any number and end with the word Contents. Currently, I'm using:

    Code:
    />\d.*Contents/
    which would then pull off ">0. Table of Contents" from:

    HTML Code:
    <a class="sf-with-ul" href="/books/Partsch_1/Table_of_Contents/table_of_contents.php">0. Table of Contents
    Truth be told, I just want "0. Table of Contents" as opposed to the opening ">". While I know that I can just use the substr() method, I'd much rather improve my somewhat non-existent regex skills. My attempt was to use

    Code:
    /\d.*Contents/
    which unfortunately pulled off

    1/Table_of_Contents/table_of_contents.php">0. Table of Contents

    Is there a cleaner regex solution?

    Thank you,

    Eric

  2. #2
    SitePoint Addict
    Join Date
    Apr 2011
    Posts
    265
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    Try with this regexp, which gets the text between '>' and '<':
    Code:
    /\>(\d.*Contents)\</
    Free: Web Programming Courses HTML, CSS, Flash
    Web Programming: AJAX Course and PHP-MySQL Course video Lessons
    Good JavaScript and jQuery course for beginners

  3. #3
    SitePoint Evangelist
    Join Date
    Mar 2011
    Location
    Bellingham, WA
    Posts
    450
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Makes sense!

    Thank you for the quick reply.


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
  •