الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مساعدة في فهم كود خاص ب Regex

بدأه OricalcosZy في 25 أغسطس 2010 · 0 رد · 402 مشاهدة · في Microsoft Visual Basic.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1

السلام عليكم ورحمة الله تعالى وبركاته

وجدت الكود التالي في أحد المشاريع الخاصة بال Regular Expression ولكني لم أفهم العديد من أجزائه

Imports System.Text.RegularExpressions
Public Class MatchingCharacters
	Inherits System.Windows.Forms.Form



	Const OnlyOneLetterRX As String = "a"

	Const LetterAandAnyRX As String = "a.b"

	Const NumbersWithPeriodRX As String = "15\.00"

	'Validate Letter a Or More
	'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	Public Function ValidateLetterA(ByVal TheString As String) As Boolean
    	Try
        	Dim rx As New Regex(OnlyOneLetterRX)
        	Return rx.IsMatch(TheString)
    	Catch ex As FormatException
        	Throw ex
    	Catch ex As Exception
        	Throw ex
    	End Try
	End Function

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    	If Me.ValidateLetterA(Me.TextBox1.Text) = True Then
        	MsgBox("Correct")
    	Else
        	MsgBox("No...(*&*)Only Letter a is Valid to be entered ... ")
    	End If
	End Sub




	'Validate A and One Or More Characters
	Public Function ValidateLetterAandAny(ByVal TheString As String) As Boolean
    	Try
        	Dim rx As New Regex(LetterAandAnyRX)
        	Return rx.IsMatch(TheString)
    	Catch ex As FormatException
        	Throw ex
    	Catch ex As Exception
        	Throw ex
    	End Try
	End Function

	Private Sub btnLetterAandAny_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLetterAandAny.Click
    	If Me.ValidateLetterAandAny(Me.txtLetterAandAny.Text) = True Then
        	MsgBox("Correct--You Enter letter a And One More Character isn't it ?")
    	Else
        	MsgBox("No..(*&*)Only 2 letters  should be Eneterd Started with Letter a  ... ")
    	End If
	End Sub





	'Validate A and One Or More Characters
	Public Function ValidateNumbersWithPeriod(ByVal TheString As String) As Boolean
    	Try
        	Dim rx As New Regex(NumbersWithPeriodRX)
        	Return rx.IsMatch(TheString)
    	Catch ex As FormatException
        	Throw ex
    	Catch ex As Exception
        	Throw ex
    	End Try
	End Function

	Private Sub btnNumbersWithPeriod_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNumbersWithPeriod.Click
    	If Me.ValidateNumbersWithPeriod(Me.txtNumbersWithPeriod.Text) = True Then
        	MsgBox("Correct--Your Number is 15.00 or More ")
    	Else
        	MsgBox("No..(*&*)Incorrect Value ... ")
    	End If
	End Sub



	Private Sub MatchingCharacters_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

	End Sub
End Class

أسئلتي :

1.مادور العبارة التالية ؟

Imports System.Text.RegularExpressions

2.ما معنى الأجزاء التالية ودور كل كلمة فيها ؟

 Public Function ValidateLetterA(ByVal TheString As String) As Boolean
    	Try
        	Dim rx As New Regex(OnlyOneLetterRX)
        	Return rx.IsMatch(TheString)
    	Catch ex As FormatException
        	Throw ex
    	Catch ex As Exception
        	Throw ex
    	End Try
	End Function

Me.ValidateLetterA(Me.TextBox1.Text) = True

تم تعديل هذه المشاركة بواسطة OricalcosZy في 25 أغسطس 2010 في 20:47

Zefri Yahya - ArabTeam 2000

tpc7rzy94tx8iduak4b.png

مواضيع مشابهة