SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Get text with RegExp

    How do I get the text from between [a] and [\a] in this string?
    Code:
    textString="please view [a]www.mysite.com[/a] for info"
    I used a really long method in my old PHP site, but would like to learn a bit of regexp in ASP.
    I did have a go...........
    Code:
    <%
    function makeLink(strToProcess)
    dim objRegExp, objMatch
    dim strConverted, strMatch
    dim linkText
    strConverted = strToProcess
    SET objRegExp = NEW RegExp
    objRegExp.pattern = "(\[a\]\w+\[\/a\])"
    objRegExp.ignoreCase = true
    objRegExp.global = false
    do while objRegExp.test(strConverted)
    SET objMatch = objRegExp.execute(strConverted)
    for each strMatch in objMatch
    linkText = replace(strMatch.Value, "\[a\]|\[\/a\]", "")
    strConverted = objRegExp.replace(strConverted, "<a href="&linkText&">"&linkText&"</a>") 
    next
    SET objMatch = NOTHING
    loop
    SET objRegExp = NOTHING
    makeLink = strConverted 
    end function
    response.write makeLink("goto [a]www.mysite.co.uk[/a] for my site")
    %>
    but no luck........... Was I close?????

    Thanks
    Last edited by Markdidj; Sep 14, 2004 at 17:16.
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  2. #2
    SEOChat has too many ads Protoss's Avatar
    Join Date
    Aug 2004
    Location
    Long Island, NY
    Posts
    248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this code out. I set it up so that it would work similar to the add a link feature in this forum so that you could have the anchor text be something other than just the plain ol' link.

    HTH,
    Jay

    Code:
    <%
    Dim X, objRegExp
    
    X="Check out [a=http://www.mysite.co.uk]my personal website[/a] !!"
    
    Set objRegExp=New RegExp
    
    objRegExp.Pattern="\[[a]=([^]]+)\]([^[]+)\[\/[a]\]"
    objRegExp.Global=True
    
    X=objRegExp.Replace(X, "<a href=""$1"" target=""_blank"">$2</a>")
    
    Set objRegExp=Nothing
    
    Response.Write(X)
    %>

  3. #3
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks Protoss.

    How do sitepoint get that special prompt box with the select dropdown on their URL input box?

    Also, if someone didn't use it and just wrote [a]mylink.com[/a] or [a]info@mysite.com[/a] I'd like to make the contents into a link or maito link

    Thanks
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  4. #4
    SEOChat has too many ads Protoss's Avatar
    Join Date
    Aug 2004
    Location
    Long Island, NY
    Posts
    248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Markdidj
    How do sitepoint get that special prompt box with the select dropdown on their URL input box?
    It's a javascript prompt box, google that and I'm sure you will find thousands of examples.

  5. #5
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I googled it and it doesn't seem to be a javascript prompt box, but a VBscript InputBox. I'll look into it abit more......
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  6. #6
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Jay, I have a previewer for the input box thats written in javascript.

    Do you ( or anybody else ) know how to do the above in javascript as well?
    I've only done word or email validating with regular expressions.

    Thanks
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  7. #7
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Kingston, Ga
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've got some code that will do it for ya. Just send me a PM mate.

  8. #8
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks cothomas, it's was answered in the javascript forum [a=http://www.sitepoint.com/forums/showthread.php?t=198218]here[/a]
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if


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
  •