Is Valid Regular Expression
Dear All,
How to check the entered search string is a valid regular expression?
Thanks in Advance
# 1 Re: Is Valid Regular Expression
what u dont want in the expr. to be regular ? what do u want to check exactly ..
any data in vb can be taken as string if it's not out of memory , so please explain what do u want the string format be .
Amahdy at 2007-11-11 17:23:28 >

# 2 Re: Is Valid Regular Expression
Dear Amadhy,
Thanks for your reply.I want to implement a find and replace search by using RichTextbox.For that i need to implement a regular expressison.I have to give a message to the user that invalid regular expression is entered in the Find text box.But how to check the string entered in the search box is a valid Regular Expression?
# 3 Re: Is Valid Regular Expression
unfortunately I can't understand u again , what flag makes your string not "Regular Expression" ??
if string = "My name is the name of my father's son" this will be "regular" ? so what will not be regular ? using what in the string will not make it "regular" that's what I want to know .
If u wish have a sample for "find and replace" u may look in this :
http://www.freevbcode.com/ShowCode.Asp?ID=2524
Amahdy at 2007-11-11 17:25:26 >

# 4 Re: Is Valid Regular Expression
If u mean that u want to prevent the user from entring some characters u may use for example InStr() to check this ; like that :
If InStr(1, ".,/=+()", "/") Then MsgBox "Invalid Character !"
where .,/=+() are the forbiden characters and "/" is the entred character from the user
[must check it every keystroke]
Amahdy at 2007-11-11 17:26:33 >

# 5 Re: Is Valid Regular Expression
Dear Amahdy,
I am using a rich text box notepad.Now I want to implement a Find and replace method by using the Regular expression. I am using this method
Dim CountallRegexp As New RegExp
Dim mc As MatchCollection
Dim mat As Match
CountallRegexp.Pattern = sFind
CountallRegexp.Global = True
If ChkMatchCase = vbChecked Then
CountallRegexp.IgnoreCase = False
Else
CountallRegexp.IgnoreCase = True
End If
Set mc = CountallRegexp.Execute(frmMain.ActiveForm.TestRTB.Text)
If the regular expression check box checked and when the user enters any special charcters like "$$$$%$%$^", this method gives a run time Error?/How to solve this problem?
Thanks in Advance.
Danasegarane :WAVE:
# 6 Re: Is Valid Regular Expression
Well u r talking about .Net environment .. U may post in the ".Net" forum to have better answer, however u can look here may this help u :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/jscript7/html/jsreconIntroductionToRegularExpressions.asp
And here is a Sample :
http://www.codeproject.com/vb/net/regexpservice.asp
It seems your pattern method problem.
Amahdy at 2007-11-11 17:28:30 >

# 7 Re: Is Valid Regular Expression
Dear Amahdy,
Thanks for your reply.I need this in VB only.