SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Regex Function Return Matched text
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jrockfl
Posting Yak Master

223 Posts

Posted - 11/12/2007 :  11:19:09  Show Profile  Visit jrockfl's Homepage  Reply with Quote
I was looking at this article, and it is close to what I need. http://sqlteam.com/forums/topic.asp?TOPIC_ID=27205
I need a function that returns that match, and does not replace it.

I pass in the RegEx pattern and it would return the matching text.
ie.
my patern is [A-Za-z]
and it would return the match from the column. Make sense?

anonymous1
Posting Yak Master

185 Posts

Posted - 11/12/2007 :  11:29:40  Show Profile  Reply with Quote
you looked at the proc in that post named dbo.regexFind, and it is not what you are looking for?
Go to Top of Page

jrockfl
Posting Yak Master

223 Posts

Posted - 11/12/2007 :  12:00:03  Show Profile  Visit jrockfl's Homepage  Reply with Quote
No, becuase it returns bit if it finds a match or not. I would like to return the matched string
Go to Top of Page

jrockfl
Posting Yak Master

223 Posts

Posted - 11/12/2007 :  12:04:44  Show Profile  Visit jrockfl's Homepage  Reply with Quote
regexReplace is close, but i do not want to replace, i want to return the matches
Go to Top of Page

anonymous1
Posting Yak Master

185 Posts

Posted - 11/12/2007 :  12:28:53  Show Profile  Reply with Quote
you should just need to create your own wrapper...

CREATE FUNCTION dbo.regexFound
(
@source varchar(5000),
@regexp varchar(1000),
@ignoreCase bit = 0
)
RETURNS varchar(5000) AS
begin
declare @found bit
set @found = dbo.regexFind(@source, @regexp, @ignoreCase)
RETURN CASE WHEN @found = 1 THEN @source ELSE NULL END
end
Go to Top of Page

jrockfl
Posting Yak Master

223 Posts

Posted - 11/12/2007 :  12:36:43  Show Profile  Visit jrockfl's Homepage  Reply with Quote
Thank you for help, but that returns the orginal text in the column without the regex applied
Go to Top of Page

anonymous1
Posting Yak Master

185 Posts

Posted - 11/12/2007 :  12:48:51  Show Profile  Reply with Quote
not sure what you mean by applied. please post your inputs and outputs.
Go to Top of Page

jrockfl
Posting Yak Master

223 Posts

Posted - 11/12/2007 :  13:42:47  Show Profile  Visit jrockfl's Homepage  Reply with Quote
I created a regex to return just the model name of a house. I have this value in the column "The Remington Elevation A"
"Remington" would be returned. This is my desired result.

Afer I apply dbo.regexReplace, my result now looks like "The Elevation A"
My matched text of "Remington" is now replaced with ''
Go to Top of Page

jrockfl
Posting Yak Master

223 Posts

Posted - 11/12/2007 :  15:03:29  Show Profile  Visit jrockfl's Homepage  Reply with Quote
Thanks for your help, I rewrote my regex to match the opposite of what I had originally matched, now that replace function works the way i needed.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.14 seconds. Powered By: Snitz Forums 2000