Regular expression to convert substring to reference

I need a regex to convert aa string to a link. I wrote something but it doesn't work in asp.net.i can't solve and i am new to regex. This function converts (bkz: string) to (bkz: show.aspx? Td = string)

Dim pattern As String = "<bkz[a-z0-9$-$&-&.-.ö-öı-ış-şç-çğ-ğü-ü\s]+)>"
Dim regex As New Regex(pattern, RegexOptions.IgnoreCase)
str = regex.Replace(str, "<a href=""show.aspx?td=$1""><font color=""#CC0000"">$1</font></a>")

      

+1


source to share


3 answers


Your regex is in trouble because of ')' without '('

Will be:

&lt;bkz:\s+((?:.(?!&gt;))+?.)&gt;

      



work better?

The first group will grab what you need.

0


source


General notes on your code: besides the absence of parentheses, you are doing unnecessary things: $ - $ is not wrong, but can only be simplified into $. The same goes for accented characters.
Everyone will tell you that the font tag is deprecated even in plain HTML: favor span with styling.

And from your question and the example in the answer, I think the expression could be something like this:

\(bkz: ([a-z0-9$&.öışçğü\s]+)\)

      



the replacement string will look like this:

(bkz: <a href=""show.aspx?td=$1""><span style=""color: #C00"">$1</span></a>)

      

BUT the first $ 1 must actually be URL encoded.

+3


source


Thanks Vonc, now it doesn't throw an error, but also When I assign str to the Label.Text method I can't see the link either. If after binding str to my label, it should be viewed in view-source;

<span id="Label1">(bkz: <a href="http://www.mysite.com?t=here">here</a>)</span>

      

But now he is at the source of the source;

<span id="Label1">(bkz: here)</span>

      

0


source







All Articles