0

I'm completely new VB.net regular expressions, however I know Perl regex pretty well, but when I tried to use perl regex type find and replaces it doesn't work. I'm trying to replace all

"figure digit", "section digit", "table digit" expressions with ignorecase

which in perl is like

Find "figure (\d+)"
Replace "<a href="fig$1">figure $1</href>"
Find "table (\d+)"
Replace "<a href="tab$1">table $1</href>" and so on

How do I achieve this in vb.net

2
  • I don't understand your goal, with "figure (\d+)" Replace "figure $1" you replace your match group by your match group so there is no effect, nop ? Commented Aug 4, 2016 at 15:18
  • now do you understand? check the edited question. Commented Aug 4, 2016 at 16:37

1 Answer 1

1

Here's an example of using Regex in VB.Net

' Top of the file

Imports System.Text.RegularExpressions

' Inside a method (for example)

' declares and initialize a regex object
Dim regexObj As New Regex("(figure|section|table) (\d+)", RegexOptions.Compiled Or RegexOptions.IgnoreCase)
' Compiled option is strictly needed here (good when reusing same regex)

' some sample text
Dim input = "some text with a figure 10 or a section 20 or a table 30"

Dim output = regexObj.Replace(input, "[$1] ($2)")
' output will be
' "some text with a [figure] (10) or a [section] (20) or a [table] (30)"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.