Reputation: 21
Dim wr_str as string
Dim str as string = "Introduction........................1"
Dim no As Match = Regex.Match(wr_str, "(^.*?)(\s*)([0-9]+)\s*$")
wr_str = Regex.Replace(wr_str, "(^.*?)(\s*)([0-9]+)\s*$", no.groups(1).value & no.groups(3).value)
Input string = "Introduction........................1"
I require the output string as 'Introduction;1'.
Could you please let me know how to change the regex expression to ignore the dots after the text
Upvotes: 2
Views: 5687
Reputation: 496
Try this regex pattern (ignorecase+multiline):
^(.*?)\.*?(\d+)$
See more - regex tester
https://i.sstatic.net/9gZBt.png
Upvotes: 0
Reputation: 627219
You can use capturing groups like this:
Dim myMatch = Regex.Match("Introduction.............1", "(^.*?)\.*([0-9]+)\s*$")
Dim res2 = myMatch.Groups(1).Value + ";" + myMatch.Groups(2).Value
Dots are captured with \.*
, and are not used for final string creation.
EDIT: To match your code context:
Dim no as Match = Regex.Match("Introduction.............1", "(^.*?)\.*([0-9]+)\s*$")
wr_str = Regex.Replace(wr_str, "(^.*?)(\.*)([0-9]+)\s*$", no.Groups(1).Value.Replace(".", "").Trim() & ";" & no.groups(2).value)
Upvotes: 1
Reputation: 425238
It seems this will do:
wr_str = Regex.Replace(wr_str, "\\.+", ";")
Upvotes: 1
Reputation: 3285
In it's simplest form, this should work:
Dim wr_str as string
Dim str as string = "Introduction........................1"
Dim no As Match = Regex.Match(wr_str, "(^.*?)(\.*)([0-9]+)\s*$")
wr_str = Regex.Replace(wr_str, "(^.*?)(\.*)([0-9]+)\s*$", no.groups(1).value & ";" & no.groups(3).value)
The regex was matching on whitespace, not dots.
Upvotes: 0