|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
[Regular Expression] match a word with interpunctuationHallo, I need to build a regular expression able to match a specified word, preceded and followed by few chars (mainly interpunctuation) Below the code. ------------------------ Explanation: let's assume the word is baby these are the 27 cases I need to match: baby baby is simply standing alone (obviously) and also these cases: baby. baby, baby; baby: baby! baby? baby baby with a following blank space baby- baby" baby' baby\ baby/ baby) and also these cases: ..Baby ,baby ;baby :baby baby baby with a preceding blank space!baby ?baby -baby "baby 'baby \baby /baby (baby and also the resulting regexp must exclude the following cases: babylon baby followed by any char lonbaby baby preceded by any char baby678 baby followed by any number 678baby baby precede by any number ------------------- This is the code: 'I have to count all the the occurences in a long text. 'I tried this code, but it didn't work: Dim myCounter As Integer = 0 Dim myMatch As Match = Nothing Dim myLongText As String = "This morning ...blah...blah.... goodnight to everyone" Dim myPattern As String = "[.;:/,-"!\?'( ]" & "baby" & "[.;:/,-"!\?') ]" myMatch = Regex.Match(myLongText, myPattern, RegexOptions.Multiline Or RegexOptions.IgnoreCase) Do While myMatch.Success myCounter = myCounter + 1 myMatch = myMatch.NextMatch Loop Debug.Write (myCounter.tostring) On Tue, 27 Jun 2006 01:58:22 +0200, teo <t**@inwind.it> wrote:
Show quoteHide quote > Does it specificaly have to be that punctuation or can it be any>This is the code: >'I have to count all the the occurences in a long text. >'I tried this code, but it didn't work: > > > >Dim myCounter As Integer = 0 > >Dim myMatch As Match = Nothing > >Dim myLongText As String = "This morning ...blah...blah.... goodnight to >everyone" > >Dim myPattern As String = "[.;:/,-"!\?'( ]" & "baby" & "[.;:/,-"!\?') ]" non-alphanumeric character? If so, some thing like: "\b" & word & "\b" should work. See "regular expressions, atomic zero-width assertions" in the help.
Controling Event Sequencing...
dataset and where clause Dataset HasChanges function not true when Dataset is passed as variable button flash with red and white color DataGridView row background color Default value not being populated in dataset How to detect datagrid row change Insert text into textbox at caret? Getting saved values back to display after Update Not 'breaking' or executing statments. |
|||||||||||||||||||||||