T
teo
I have a problem (partial).
Some days ago I asked for a way
to extract a word and few text around it
(30 chars on the left and 30 on the right)
from a long text.
I went good with:
..{1,30}?myWord.{1,30}
----- here the code: -------------
' Let's assume the target word is "carcass"
Dim Input As String = "Sylvia Brunner, a marine mammals
researcher at the museum in Fairbanks, identified
the decomposing carcass and oversaw its recovery on Wednesday.
The bloated, black thing on the beach
was about 12 feet from the river's edge"
Dim Pattern As String = ".{1,30}?carcass.{1,30}"
Dim myMatch As Match = Nothing
myMatch = Regex.Match(Input, Pattern, RegexOptions.Multiline)
If myMatch.Success Then
Debug.WriteLine(myMatch.Value)
End If
----------------
BUT...
if the word is at very beginning or at very ending
of the phrase (ie: "Sylvia" or "edge" )
the RegEx fails.
How to match also these extreme cases?
Some days ago I asked for a way
to extract a word and few text around it
(30 chars on the left and 30 on the right)
from a long text.
I went good with:
..{1,30}?myWord.{1,30}
----- here the code: -------------
' Let's assume the target word is "carcass"
Dim Input As String = "Sylvia Brunner, a marine mammals
researcher at the museum in Fairbanks, identified
the decomposing carcass and oversaw its recovery on Wednesday.
The bloated, black thing on the beach
was about 12 feet from the river's edge"
Dim Pattern As String = ".{1,30}?carcass.{1,30}"
Dim myMatch As Match = Nothing
myMatch = Regex.Match(Input, Pattern, RegexOptions.Multiline)
If myMatch.Success Then
Debug.WriteLine(myMatch.Value)
End If
----------------
BUT...
if the word is at very beginning or at very ending
of the phrase (ie: "Sylvia" or "edge" )
the RegEx fails.
How to match also these extreme cases?