SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Length of search result

    Code example to search for html <div> tag:

    index = html.search(/<div>|<div .*>/i);

    As you can see it also searches for anything inside the div tag; e.g., <div style="color:#00FF00">

    Any recommendations how to find the length of the search result? For example <div> is 5 characters, while <div style="color:#00FF00"> is 27 characters.

    The only way I know how to do it is with two searches. The above search, then search for the ending > character to get the length.

    Thanks,
    Paul

  2. #2
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    I'm not quite sure I get the problem.

    What is the end-result you are trying to achieve with this?

  3. #3
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's for a html tidy function I'm writing for a WYSIWYG.

  4. #4
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    What's this portion of the function supposed to do? When I write them I generally just kill whitespace in between elements with a simple regex. Can you elaborate a bit more?


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
  •