REGEX_GREP Function
Syntax
Arguments
- New_String
The lines or elements that match the Search_Expresssion.
- text
The character string to examine. The parentheses characters " ( " and " ) " have special meaning. If present, they enclose a regular expression argument. If you want parentheses characters to be part of the text, you must precede them with " \ " characters.
- RegExp
A regular expression that contains one or more search arguments. Refer to Regular Expressions for detailed information.
- Format
Character
- "\0" = All text.
- "\N" = Tagged text expression.
- "N" = No copy of unmatched text.
- "F" = Only process first match.
- "$(OFFSET)" = Return the offset of the match.
- "$(LENGTH)" = Return the length of the match.
- "$(END)" = Return the ending offset of the match.
- "$(LINE)" = Return the line the match started on.
- "$(ENDLINE)" = Return the line the match ended on.
- "$(LINES)" = Return the number of lines the match crosses.
- "$(LINETEXT)" = Return the complete line(s) of text the match(es) occurred on.
- "$(LINEOFFSET)" = Return the offset of the beggining of the match line.
- "$(ENDLINEOFFSET)" = Return the offset of the end of the line the match ended on.
- "$(COUNT)" = Return the number of matches encountered so far.
- "$(NEXTLINE)" = Advance the search pointer to the next line.
- options
Optional. Default = "S". Specify which compatibility with a common implementation. ThE flags for Emacs, Awk, Grep, Egrep and Sed conventions allow the pattern to follow the conventions of those utilities (which have slightly different variants regarding what is escaped and what is not escaped).
- "I" = Ignore case
- "E" = Follow Emacs conventions
- "A" = Follow Awk conventions
- "G" = Follow Grep conventions
- "EG" = Follow Egrep conventions
- "S" = Follow Sed conventions
- "X" = Extended (similar to Awk but no need to escape '' inside of [])
Description
Performs a regex grep on text. format takes \0 for all text \N for tagged expression. options same as regex_match with additional options: N No copy of unmatched text. F Only process first match.
Discussion
The REGEX_GREP() function returns information about or text elements from the target text or list that match a regular expression. It offers functionality above and beyond GREP, especially when used in the context of Xbasic.
Example
dim cc as C cc = file.to_string("c:\ALPHA4V8\README.TXT") ? regex_grep(cc, "(W|w)indows", "$(LINETEXT)" + crlf() ) =Running With Windows 95 Using Alpha Four with Microsoft Windows for Workgroups Running With Windows 95 Four to crash when running Windows 95. To avoid this problem, do the Using Alpha Four with Microsoft Windows for Workgroups To configure Windows for Workgroups to work properly with Alpha Four, Field Rules: Lookup Windows can Now Use Custom Column Headings and Custom
The REGEX_GREP() function acts like the command line GREP utility if you use the format.
"$(OFFSET%4d) : (LINETEXT)" + crlf()
This example returns the offset to each occurrence of a word.
dim cc as C cc = <<%a% My house has 3 doors and 26 windows I don't miss Windows 3.1 Who does? Ira, did you leave the window open? %a% txt = regex_grep(cc, "(W|w)indow", "$(offset): $(LINETEXT)" + crlf() ) ? txt = 30: and 26 windows 52: I don't miss Windows 3.1 99: Ira, did you leave the window open?
See Also