Difference between revisions of "FindInText"

Line 37: Line 37:
 
:[[FindInText]]("\w{4}","Now is the time for",re:True, return:'S') → 'time'
 
:[[FindInText]]("\w{4}","Now is the time for",re:True, return:'S') → 'time'
 
:[[FindInText]]("\w{4}\w*","We the people, in order to...",re:True,return:['S','L','P']) → ['people',6,8]
 
:[[FindInText]]("\w{4}\w*","We the people, in order to...",re:True,return:['S','L','P']) → ['people',6,8]
 +
 +
A [[regular expression]] may contain subpatterns.  These are delineated within the [[regular expression]] through the use of parenthesis, and are numbered in a depth-first fashion.  They can also be used using the syntax ''(?<name>...)''.  You can return information on a specific subpattern (or an array of subpatterns) by specifying which subpattern is of interest in the optional «subpattern» parameter:
 +
 +
:[[FindInText]]("to (\w+)","We the people, in order to form a more...",re:True,subpattern:1) &rarr; 28
 +
:[[FindInText]]("to (\w+)","We the people, in order to form a more...",re:True,subpattern:1,return:'S') &rarr; 'form'
 +
:[[FindInText]]("to (?<verb>\w+)","We the people, in order to form a more...",re:True,subpattern:'verb') &rarr;28
 +
  
 
For more details, see [[Regular Expressions]].
 
For more details, see [[Regular Expressions]].

Revision as of 17:34, 23 February 2009


FindInText( substr, text, start, caseInsensitive )

Returns the position of the first occurrence of «substr» in «text». If «substr» does not occur in «text», returns 0. The optional third parameter, «start», specifies the position to start searching at. You can specify the fourth parameter, «caseInsensitive», as True to signify that upper and lower variants of the same characters match.

Library

Text Functions

Examples

FindInText("is","Now is not the time") → 5
FindInText("i","Now is not the time") → 5
FindInText("i","Now is not the time","i") → 17
FindInText("now","Now is not the time") → 0
FindInText("no","Now is not the time") → 8
FindInText("no","Now is not the time",caseInsensitive:True) → 1

Regular Expressions

New to Analytica 4.2

When the optional parameter «re» is set to True, «substr» is interpreted as a regular expression. For example, the following find the location of the first vowel:

FindInText("[aeiou]","Now is not the time",re:True,caseInsensitive:True) → 2

When matching a pattern, you may want information other than just the starting position. The optional parameter «return» specifies what information about the match is desired. «Return» can be specified as any of the following (or an array of any of these):

  • 'P' (or 'Position'): The position in the subject text where the matched pattern was found, or zero if not found.
  • 'L' (or 'Length'): The length of the match in the subject text.
  • 'S' (or 'SubPattern'): The subtext matched by the pattern
  • '#' (or '#SubPatterns'): The number of subpatterns in the regular expression.

Examples:

FindInText("[aeiou]","Now is the time for",re:True,return:'S') → 'o'
FindInText("\w{4}","Now is the time for",re:True, return:'S') → 'time'
FindInText("\w{4}\w*","We the people, in order to...",re:True,return:['S','L','P']) → ['people',6,8]

A regular expression may contain subpatterns. These are delineated within the regular expression through the use of parenthesis, and are numbered in a depth-first fashion. They can also be used using the syntax (?<name>...). You can return information on a specific subpattern (or an array of subpatterns) by specifying which subpattern is of interest in the optional «subpattern» parameter:

FindInText("to (\w+)","We the people, in order to form a more...",re:True,subpattern:1) → 28
FindInText("to (\w+)","We the people, in order to form a more...",re:True,subpattern:1,return:'S') → 'form'
FindInText("to (?<verb>\w+)","We the people, in order to form a more...",re:True,subpattern:'verb') →28


For more details, see Regular Expressions.

See Also

Comments


You are not allowed to post comments.