Satimage Previous
find text
Home Documentation Smile Text commands find text  
find text search text for regular strings or for regular expression patterns: to toggle into regular expression mode you specify find text [...] with regexp. If needed, find text will convert the direct parameter and the in parameter into Unicode text.
find textfind text literally or using regular expression syntax.
string/Unicode text -- the substring (or regular expression) to search for
in string/Unicode text -- a string or an alias
[starting at] integer -- default: 0
[for] integer -- length of text after starting
[case sensitive] boolean -- default true
[regexp] boolean -- use regular expression, default false
[whole word] boolean -- only without regexp. default false
[regexpflag] list of string -- a subset of {"IGNORECASE", "EXTEND", "MULTILINE", "SINGLELINE", "FIND LONGEST", "FIND NOT EMPTY", "DONT CAPTURE GROUP", "NOTBOL", "NOTEOL"}; default {}
[using] string -- the pattern to generate the string (regexp). Useful for constructs with backward references in regexp, ex.: using "name: \\1". May be a list of strings, in this case matchResult is a list of strings.
[all occurrences] boolean -- returns a list of all occurrences. Default: false
[string result] boolean -- return only the matching string instead of the whole record
[syntax] string -- the syntax for regular expressions. Relevant if regexp parameter is true. A string among ("POSIX" | "POSIX_EXTENDED" | "EMACS" | "GREP" | "GNU_REGEX" | "JAVA" | "PERL" | "RUBY"). Default: "RUBY"
Result: record -- {matchLen: length of the match, matchPos: offset of the match (0 is the first character!), matchResult: the matching string (possibly formatted according to the "using" parameter)}
  • If there is no match find text returns an error, except when used with the all occurrences option, which will simply return an empty list.
  • find text accepts a reference to a file as their in parameter, instead of a string.
  • find text accepts a reference to a text window or a Unicode window of Smile as its in parameter.
  • You can also pass descriptors to pieces of text in a window such as selection of the_window.
  • The using parameter is to tailor the returned string.
    • The using parameter supports strings and lists of strings.
    • Those strings recognize the following metacharacters: \0, which stands for the whole match, and \1 ... \9, which references the successive groups (parentheses, by order of the opening parenthesis) which where defined in the search pattern.
    • The using parameter recognizes the special characters \r, \n and \t which stand respectively for CR, LF, and tab.
Examples
find text "@" in paragraph 2 of window 2

set the_str to pi as string
find text "3" in the_str
  --  {matchPos:0, matchLen:1, matchResult:"3"}

set the_file to (path to preferences from user domain)
set the_file to (the_file as text) & "com.apple.Safari.plist"
set the_file to the_file as alias
find text "<string>(.*)</string>" in the_file using "\\1" with regexp, all occurrences and string result
-- lists the strings stored in Safari's prefs
Copyright ©2008 Paris, Satimage