Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
RegExp question
Message
From
08/02/2017 15:43:25
 
 
To
08/02/2017 14:04:58
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01647702
Message ID:
01647722
Views:
51
Excelent. and with little more doctoring I added the Function too. plus including the name that follows.
clear
TEXT TO cText NOSHOW TEXTMERGE
DEFINE CLASS test
	PROCEDURE init
		IF ATC("DEFINE CLASS",x)>0
		*
		ENDIF 
		IF ATC("PROCEDURE",x)>0
		*
		ENDIF 
		PROTECTED PROCEDURE something
		ENDPROC 
		HIDDEN PROCEDURE more_sss
		ENDPROC 
		FUNCTION me(xx)
		ENDFUNC 
	ENDPROC
ENDDEFINE 
ENDTEXT

RegExp = NEWOBJECT( "_RegExp", "RegExp.vcx" )
cpat = "^\s*(((hidd(e(n)?)?)|(prot(e(c(t(e(d)?)?)?)?)?))\s+)?((func(t(i(o(n)?)?)?)?)|(proc(e(d(u(r(e)?)?)?)?)?))\s*\w+"
? cpat
n=  RegExp.execute( ctext, cpat, .F., .T.)
? n
FOR i=1 TO n
	?
*	?? RegExp.Matches[i,1]
	?? RegExp.Matches[i,2]
*	?? substr(ctext, regexp.matches(i,1), 20)
NEXT 
>Looking for HIDDEN and PROTECTED modifiers, as well as the truncated forms of the keywords, is a very nice touch, Thierry. Well done.
>
>A different approach for the pattern that looks for PROCEDURE, but following your lead on those two aspects:
>
>
>m.RegEx.Pattern = "^\s*(((hidd(e(n)?)?)|(prot(e(c(t(e(d)?)?)?)?)?))\s+)?(proc(e(d(u(r(e)?)?)?)?)?)\s"
>
>
>
>
>>Hi Greg,
>>
>>Looking at modify class _regexp of Ffc\_regexp.vcx method execute, it misses the multiline option.
>>
>>LParameters tcStr, tlCaseMatters
>>
>>Local loRegEx, loMatch, loMatches, i
>>
>>loRegEx = CreateObject("VBScript.RegExp")
>>loRegEx.pattern = this.pattern
>>loRegEx.ignoreCase = !tlCaseMatters
>>loRegEx.global = .T.
>>
>>loMatches = loRegEx.execute(tcStr)
>>Dimension this.matches[Max(loMatches.count,1),2]
>>taMatchInfo = .F.
>>
>>i = 1
>>For Each loMatch In loMatches
>>	this.matches[i, 1] = loMatch.firstIndex + 1   && fox strings are not zero-based
>>	this.matches[i, 2] = loMatch.value
>>	i = i + 1
>>EndFor
>>
>>loMatches = .F.
>>loRegEx = .F.
>>
>>Return i -1
>>
>>
>>You need to instantiate "VBScript.RegExp" yourself:
>>
>>loRegEx = CreateObject("VBScript.RegExp")
>>loRegEx.pattern = this.pattern
>>loRegEx.ignoreCase = !tlCaseMatters
>>loRegEx.global = .T.
>>loRegEx.multiline = .T.
>>
>>
>>Then this pattern should work:
>>
>>(^[ \t]*(?=[_\u0041-\u005A\u005F\u0061-\u007A\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF\u0152-\u0153\u0160-\u0161\u0178\u0192#@&=\?\.\\](?!&))(?:(?:HIDD(?:E|EN)?|PROT(?:E|EC|ECT|ECTE|ECTED)?)(?:[ \t]+|(?:[ \t]*;\s*?(?=&&|$).*?$\s+)))*(?:FUNC(?:T|TI|TIO|TION)?|PROC(?:E|ED|EDU|EDUR|EDURE)?)
>>
>>
>>
>>
>>>Have been trying to construct a Regular Expression pattern to find a string that only exists at the beginning of a line, even if there are none or more white spaces before it (either spaces or tabs).
>>>
>>>Example text I'm search
>>>
>>>
>>>DEFINE CLASS test
>>>	PROCEDURE init
>>>		IF ATC("DEFINE CLASS",x)>0
>>>		*
>>>		ENDIF 
>>>		IF ATC("PROCEDURE",x)>0
>>>		*
>>>		ENDIF 
>>>	ENDPROC
>>>	PROCEDURE destroy
>>>	ENDPROC
>>>ENDDEFINE 
>>>
>>>
>>>If I am look for the "DEFINE CLASS" (ignoring the case), I would like for it to find only the "DEFINE CLASS test". Also, If I am looking for "PROCEDURE", I want it to find only the "PROCEDURE init" and "PROCEDURE destory", not the one in the ATC().
>>>
>>>Here is a example of the search code I am trying.
>>>
>>>
>>>RegExp = NEWOBJECT( "_RegExp", "RegExp.vcx" )
>>>ctext=FILETOSTR("tt.prg")
>>>? RegExp.execute( ctext, [(\bdefine class\b)], .F., .T.)
>>>? RegExp.execute( ctext, [(\bprocedure\b)], .F., .T.)
>>>
>>>
>>>I realize I need to be including the '^' (start of line), possibly '\s*' for the white spaces. but when I do include them the query fails to find anything. I only want it to find matches that are at the beginning of the lines.
Greg Reichert
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform