EVOLUTION-MANAGER
Edit File: stri_locate.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Locate Occurrences of a Pattern</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for stri_locate_all {stringi}"><tr><td>stri_locate_all {stringi}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Locate Occurrences of a Pattern</h2> <h3>Description</h3> <p>These functions may be used, e.g., to find the indexes (positions) where there is a match to some pattern. The functions <code>stri_locate_all_*</code> locate all the matches. <code>stri_locate_first_*</code> and <code>stri_locate_last_*</code> give the first or the last matches, respectively. </p> <h3>Usage</h3> <pre> stri_locate_all(str, ..., regex, fixed, coll, charclass) stri_locate_first(str, ..., regex, fixed, coll, charclass) stri_locate_last(str, ..., regex, fixed, coll, charclass) stri_locate( str, ..., regex, fixed, coll, charclass, mode = c("first", "all", "last") ) stri_locate_all_charclass(str, pattern, merge = TRUE, omit_no_match = FALSE) stri_locate_first_charclass(str, pattern) stri_locate_last_charclass(str, pattern) stri_locate_all_coll( str, pattern, omit_no_match = FALSE, ..., opts_collator = NULL ) stri_locate_first_coll(str, pattern, ..., opts_collator = NULL) stri_locate_last_coll(str, pattern, ..., opts_collator = NULL) stri_locate_all_regex( str, pattern, omit_no_match = FALSE, ..., opts_regex = NULL ) stri_locate_first_regex(str, pattern, ..., opts_regex = NULL) stri_locate_last_regex(str, pattern, ..., opts_regex = NULL) stri_locate_all_fixed( str, pattern, omit_no_match = FALSE, ..., opts_fixed = NULL ) stri_locate_first_fixed(str, pattern, ..., opts_fixed = NULL) stri_locate_last_fixed(str, pattern, ..., opts_fixed = NULL) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>str</code></td> <td> <p>character vector; strings to search in</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>supplementary arguments passed to the underlying functions, including additional settings for <code>opts_collator</code>, <code>opts_regex</code>, <code>opts_fixed</code>, and so on</p> </td></tr> <tr valign="top"><td><code>mode</code></td> <td> <p>single string; one of: <code>"first"</code> (the default), <code>"all"</code>, <code>"last"</code></p> </td></tr> <tr valign="top"><td><code>pattern, regex, fixed, coll, charclass</code></td> <td> <p>character vector; search patterns; for more details refer to <a href="stringi-search.html">stringi-search</a></p> </td></tr> <tr valign="top"><td><code>merge</code></td> <td> <p>single logical value; indicates whether consecutive sequences of indexes in the resulting matrix should be merged; <code>stri_locate_all_charclass</code> only</p> </td></tr> <tr valign="top"><td><code>omit_no_match</code></td> <td> <p>single logical value; if <code>FALSE</code>, then two missing values will indicate that there was no match; <code>stri_locate_all_*</code> only</p> </td></tr> <tr valign="top"><td><code>opts_collator, opts_fixed, opts_regex</code></td> <td> <p>a named list used to tune up the search engine's settings; see <code><a href="stri_opts_collator.html">stri_opts_collator</a></code>, <code><a href="stri_opts_fixed.html">stri_opts_fixed</a></code>, and <code><a href="stri_opts_regex.html">stri_opts_regex</a></code>, respectively; <code>NULL</code> for the defaults</p> </td></tr> </table> <h3>Details</h3> <p>Vectorized over <code>str</code> and <code>pattern</code> (with recycling of the elements in the shorter vector if necessary). This allows to, for instance, search for one pattern in each given string, search for each pattern in one given string, and search for the i-th pattern within the i-th string. </p> <p>The matches may be extracted by calling <code><a href="stri_sub.html">stri_sub</a></code> or <code><a href="stri_sub_all.html">stri_sub_all</a></code>. Alternatively, you may call <code><a href="stri_extract.html">stri_extract</a></code> directly. </p> <p><code>stri_locate</code>, <code>stri_locate_all</code>, <code>stri_locate_first</code>, and <code>stri_locate_last</code> are convenience functions. They just call <code>stri_locate_*_*</code>, depending on the arguments used. </p> <h3>Value</h3> <p>For <code>stri_locate_all_*</code>, a list of integer matrices is returned. Each list element represents the results of a separate search scenario. The first column gives the start positions of the matches, and the second column gives the end positions. Moreover, you may get two <code>NA</code>s in one row for no match (if <code>omit_no_match</code> is <code>FALSE</code>) or <code>NA</code> arguments. </p> <p><code>stri_locate_first_*</code> and <code>stri_locate_last_*</code> return an integer matrix with two columns, giving the start and end positions of the first or the last matches, respectively, and two <code>NA</code>s if and only if they are not found. </p> <p>For <code>stri_locate_*_regex</code>, if the match is of zero length, <code>end</code> will be one character less than <code>start</code>. </p> <h3>See Also</h3> <p>Other search_locate: <code><a href="stri_locate_boundaries.html">stri_locate_all_boundaries</a>()</code>, <code><a href="stringi-search.html">stringi-search</a></code> </p> <p>Other indexing: <code><a href="stri_locate_boundaries.html">stri_locate_all_boundaries</a>()</code>, <code><a href="stri_sub_all.html">stri_sub_all</a>()</code>, <code><a href="stri_sub.html">stri_sub</a>()</code> </p> <h3>Examples</h3> <pre> stri_locate_all('XaaaaX', regex=c('\\p{Ll}', '\\p{Ll}+', '\\p{Ll}{2,3}', '\\p{Ll}{2,3}?')) stri_locate_all('Bartolini', fixed='i') stri_locate_all('a b c', charclass='\\p{Zs}') # all white spaces stri_locate_all_charclass(c('AbcdeFgHijK', 'abc', 'ABC'), '\\p{Ll}') stri_locate_all_charclass(c('AbcdeFgHijK', 'abc', 'ABC'), '\\p{Ll}', merge=FALSE) stri_locate_first_charclass('AaBbCc', '\\p{Ll}') stri_locate_last_charclass('AaBbCc', '\\p{Ll}') stri_locate_all_coll(c('AaaaaaaA', 'AAAA'), 'a') stri_locate_first_coll(c('Yy\u00FD', 'AAA'), 'y', strength=2, locale="sk_SK") stri_locate_last_coll(c('Yy\u00FD', 'AAA'), 'y', strength=1, locale="sk_SK") pat <- stri_paste("\u0635\u0644\u0649 \u0627\u0644\u0644\u0647 ", "\u0639\u0644\u064a\u0647 \u0648\u0633\u0644\u0645XYZ") stri_locate_last_coll("\ufdfa\ufdfa\ufdfaXYZ", pat, strength = 1) stri_locate_all_fixed(c('AaaaaaaA', 'AAAA'), 'a') stri_locate_all_fixed(c('AaaaaaaA', 'AAAA'), 'a', case_insensitive=TRUE, overlap=TRUE) stri_locate_first_fixed(c('AaaaaaaA', 'aaa', 'AAA'), 'a') stri_locate_last_fixed(c('AaaaaaaA', 'aaa', 'AAA'), 'a') #first row is 1-2 like in locate_first stri_locate_all_fixed('bbbbb', 'bb') stri_locate_first_fixed('bbbbb', 'bb') # but last row is 3-4, unlike in locate_last, # keep this in mind [overlapping pattern match OK]! stri_locate_last_fixed('bbbbb', 'bb') stri_locate_all_regex('XaaaaX', c('\\p{Ll}', '\\p{Ll}+', '\\p{Ll}{2,3}', '\\p{Ll}{2,3}?')) stri_locate_first_regex('XaaaaX', c('\\p{Ll}', '\\p{Ll}+', '\\p{Ll}{2,3}', '\\p{Ll}{2,3}?')) stri_locate_last_regex('XaaaaX', c('\\p{Ll}', '\\p{Ll}+', '\\p{Ll}{2,3}', '\\p{Ll}{2,3}?')) # Use regex positive-lookahead to locate overlapping pattern matches: stri_locate_all_regex("ACAGAGACTTTAGATAGAGAAGA", "(?=AGA)") # note that start > end here (match of 0 length) </pre> <hr /><div style="text-align: center;">[Package <em>stringi</em> version 1.4.6 <a href="00Index.html">Index</a>]</div> </body></html>