|
|
Subject:
SQL Query, Stripping data in a field.
Category: Computers > Programming Asked by: apcs_uk-ga List Price: $10.00 |
Posted:
12 Dec 2003 03:06 PST
Expires: 11 Jan 2004 03:06 PST Question ID: 286283 |
Hi, I have a list or URLs in a column (field name URLs). http://www.domain.com http://1.domain.com http://shop.domain.com shopping.domain.com etc. I want to bring these urls into an asp list page and order alphabeticaly. Which means that, where applicable, i need to strip the http:// and www. out. How can i do this with a query? Also, if i have a field with a first and surname, how can i return just the first or second name in a query. I think i need to use regular expressions but i have never used them before and they look kinda scary :) Many thanks | |
| |
| |
| |
| |
|
|
Subject:
Re: SQL Query, Stripping data in a field.
Answered By: joseleon-ga on 13 Dec 2003 01:48 PST Rated: |
Hello, apcs_uk: Here you have a sample ASP scripts that shows you how to extract urls from a text and then extract all the pieces that make up the URLs, including the domain name, the part you are interested in: <%@ Language=VBScript %> <% Option Explicit 'Declare our variable Dim objRegExpr 'Create an instance of the regexp object Set objRegExpr = New regexp objRegExpr.Pattern = "(http:\/\/|https:\/\/|ftp:\/\/|)(([A-Z0-9][A-Z0-9_-]*\.)(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)))" objRegExpr.Global = True objRegExpr.IgnoreCase = True 'What string are we searching on? Dim strSearchOn strSearchOn = "You can searc http://www.domain.com for URLs in any text " & _ "string http://1.domain.com/ and http://shop.domain.com/ extract all that matches the regular shopping.domain.com expression" 'Declare a variable to hold our collection of Matches Dim colMatches 'Now, Execute the regular expression search Set colMatches = objRegExpr.Execute(strSearchOn) Dim objMatch 'Print the # of matches we found Response.Write colMatches.Count & " matches found...<P>" 'Step through our matches For Each objMatch in colMatches Response.Write "<HR>" Response.Write "Full URL: " & objMatch.Value & "<BR>" Response.Write "Protocol: " & objMatch.SubMatches(0) & "<BR>" Response.Write "URL w/o domain: " & objMatch.SubMatches(1) & "<BR>" Response.Write "First part: " & objMatch.SubMatches(2) & "<BR>" Response.Write "Domain name: " & objMatch.SubMatches(3) & "<BR>" Next 'Clean up Set colMatches = Nothing Set objRegExpr = Nothing %> Be aware of the word wrapping when copying and pasting. This script produces the following results: 4 matches found... -------------------------------------------------------------------------------- Full URL: http://www.domain.com Protocol: http:// URL w/o domain: www.domain.com First part: www. Domain name: domain.com -------------------------------------------------------------------------------- Full URL: http://1.domain.com Protocol: http:// URL w/o domain: 1.domain.com First part: 1. Domain name: domain.com -------------------------------------------------------------------------------- Full URL: http://shop.domain.com Protocol: http:// URL w/o domain: shop.domain.com First part: shop. Domain name: domain.com -------------------------------------------------------------------------------- Full URL: shopping.domain.com Protocol: URL w/o domain: shopping.domain.com First part: shopping. Domain name: domain.com I hope this is what you were looking for, don't hesitate to request for any clarification. You can get a lot of information about regular expressions applied to asp in this page: Regular Expression Information http://www.4guysfromrolla.com/webtech/regularexpressions.shtml Regards. |
apcs_uk-ga
rated this answer:
and gave an additional tip of:
$5.00
Fantastic, worked almost straight off. Also very well commented. |
|
There are no comments at this time. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |