Forum Moderators: open
The text to look for will always look like this:
(OTCBB:ZZZZ)
where ZZZZ is the ticker. Those will change (sometimes 2 through 5 characters so I can't do it based on number of spaces - has to be based on the closing paranthesis). They will always be prefaced by (OTCBB: and end with a close ")". So what's the RegEx.Replace line I need to use here to make whatever comes after (OTCBB: and before the next ")" a hyperlink. The catch is that the ticker must be in the hyperlink so I think that uses like a $1 or $2 type thing but I really can't remember, been so long since I used a RegEx for anything.
Off the top of my head I think this might do it. using a named capture.\(OTCBB:(?'ticker'[^\)]*)
The thing is, I don't know what the ticker is going to be. There will be several different ones and no way to guess at which one they are - but the structure will always be the same. I know there is a way to do this using $1 or something, but for the life of me I can't find it.
Dim testString As String = "This is a test of tickers (OTCBB:MSFT) and (OTCBB:CIEN)"
Dim pattern As String = "\(OTCBB:(?<ticker>[A-Z]{2,5})\)"
Dim replacement As String = "(OTCBB:<a href=http://example.com/page.asp?ticker=${ticker}>${ticker}</a>)"
Dim newString As String
Dim regEx As Regex
newString = regEx.Replace(testString, pattern, replacement)
This will produce the following result:
This is a test of tickers (OTCBB:<a href=http://example.com/page.asp?ticker=MSFT>MSFT</a>) and (OTCBB:<a href=http://example.com/page.asp?ticker=CIEN>CIEN</a>)
[edited by: TheNige at 9:15 pm (utc) on Aug. 16, 2006]