Forum > ASP.NET 3.x > Språk - VB.NET
Jag försöker lära mig lite Regular Expressions.
Och det går väl hyffsat, men när jag ska matcha om användaren skrivit in en <script> tag, vill jag ersätta den.
Jag har den här koden:
regExp = New Regex("\<script\>([^\]]+)\]([^\]]+)\<\/script\>")
strTextToReplace = regExp.Replace(strTextToReplace, "< s/c/r/i/p/t >$1< / s/c/r/i/p/t >")
| Skriv utDitt uttryck gör just nu:
Match the character “<” literally «\<»
Match the characters “script” literally «script»
Match the character “>” literally «\>»
Match the regular expression below and capture its match into backreference number 1 «([^\]]+)»
Match any character that is not a “A ] character” «[^\]]+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match the character “]” literally «\]»
Match the regular expression below and capture its match into backreference number 2 «([^\]]+)»
Match any character that is not a “A ] character” «[^\]]+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match the character “<” literally «\<»
Match the character “/” literally «\/»
Match the characters “script” literally «script»
Match the character “>” literally «\>»
Du vill nog bara använda dig av
<script>([\w\W]*?)<\/script>
tackar, det löste det.