> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/string/refind.md).

# ReFind

Uses a regular expression (RE) to search a string for a pattern, starting from a specified position.

The search is case-sensitive. It will return numeric if returnsubexpressions is false and a struct of arrays named "len", "match" and "pos" when returnsubexpressions is true.

## Method Signature

```
ReFind(reg_expression=[string], string=[string], start=[integer], returnSubExpressions=[boolean], scope=[string])
```

### Arguments

| Argument               | Type      | Required | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | Default |
| ---------------------- | --------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `reg_expression`       | `string`  | `true`   | The regular expression to search for                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |         |
| `string`               | `string`  | `true`   | The string to serach in                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |         |
| `start`                | `integer` | `false`  | The position from which to start searching in the string. Default is 1.                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | `1`     |
| `returnSubExpressions` | `boolean` | `false`  | <p>True: if the regular expression is found, the first array element contains the length and position, respectively, of<br>the first match. If the regular expression contains parentheses that group subexpressions, each subsequent array<br>element contains the length and position, respectively, of the first occurrence of each group. If the regular<br>expression is not found, the arrays each contain one element with the value 0. False: the function returns the<br>position in the string where the match begins. Default.</p> | `false` |
| `scope`                | `string`  | `false`  | "one": returns the first value that matches the regex. "all": returns all values that match the regex.                                                                                                                                                                                                                                                                                                                                                                                                                                        | `one`   |

## Examples

### Script Syntax

[Run Example](https://try.boxlang.io/?code=eJwrSnXLzEvxy3dOLE7VUFByVdJRUCpJLS5RMDQyVlRS0LTmAgC4MAkY)

```java
reFindNoCase( "E", "test 123!" );

```

Result: 2

### Script Syntax

CF2016+ example with all optional arguments

[Run Example](https://try.boxlang.io/?code=eJzzCvb3C04tykzMyaxK1VAoSnXLzEvxy3dOLAbylFyVdBSUSlKLSxQMjYwVgRxDHYWSotJUoKijj4%2BSgqaCpjUXAMLsEn0%3D)

```java
JSONSerialize( reFindNoCase( "E", "test 123!", 1, true, "ALL" ) );

```

Result: \[{"len":\[1],"pos":\[2],"match":\["e"]}]

### Additional Examples

[Run Example](https://try.boxlang.io/?code=eJyNjsFLwzAYxe%2F7Kz5z2Fo7Bs30siEj1HkSD2OCkOXwNY22uKYlyZj%2B937ZPGyCOkjII7z3fm%2FvmmDud22fwGr50NjqqSvQmwQYZjpjY3pLjVgUVcUghXQ%2B2P%2BVuI4JQQmhL0nIzWKonOnhDmKQVOfCRL%2B2i%2BNnzqc3wx2J2wvgsaFERPGvd3KY%2BW0LxgcfXGPf8jhjXRvQGKCxEEjWJOPV2BooUb9fsfnAh2g9llJdIkdyhtu%2BxpkaqSyVoLJkk6cEOSkfAx22Xj0v2Y91VCeBbY1loCRMQZ3P4nGWEOKFrjjQ%2BSn94wzDf8egc%2Fj5aGwEcgL2nWeRFW1fc4uWkg%3D%3D)

```java
writeDump( REFindNoCase( "a+c+", "abcaaCCdd" ) );
writeDump( REFindNoCase( "a+c*", "AbcaAcCdd" ) );
writeDump( REFindNoCase( "[\?&]rep = ", "report.bxm?rep = 1234&u = 5" ) );
writeDump( REFindNoCase( "a+", "baaaA" ) );
writeDump( REFindNoCase( ".*", "" ) );
teststring1 = "The cat in the hat hat came back!";
st1 = REFind( "(['[:alpha:]']+)[ ]+(\1)", teststring1, 1, "TRUE" );
writeDump( st1[ "len" ][ 3 ] );
teststring2 = "AAAXAAAA";
st2 = REFind( "x", teststring2, 1, "TRUE" );
writeDump( arrayLen( st2[ "pos" ] ) );

```

## Related

* [Ascii](/boxlang-language/reference/built-in-functions/string/ascii.md)
* [CamelCase](/boxlang-language/reference/built-in-functions/string/camelcase.md)
* [Char](/boxlang-language/reference/built-in-functions/string/char.md)
* [CharsetDecode](/boxlang-language/reference/built-in-functions/string/charsetdecode.md)
* [CharsetEncode](/boxlang-language/reference/built-in-functions/string/charsetencode.md)
* [Compare](/boxlang-language/reference/built-in-functions/string/compare.md)
* [CompareNoCase](/boxlang-language/reference/built-in-functions/string/comparenocase.md)
* [Find](/boxlang-language/reference/built-in-functions/string/find.md)
* [FindNoCase](/boxlang-language/reference/built-in-functions/string/findnocase.md)
* [FindOneOf](/boxlang-language/reference/built-in-functions/string/findoneof.md)
* [Insert](/boxlang-language/reference/built-in-functions/string/insert.md)
* [JSStringFormat](/boxlang-language/reference/built-in-functions/string/jsstringformat.md)
* [Justify](/boxlang-language/reference/built-in-functions/string/justify.md)
* [KebabCase](/boxlang-language/reference/built-in-functions/string/kebabcase.md)
* [LCase](/boxlang-language/reference/built-in-functions/string/lcase.md)
* [Left](/boxlang-language/reference/built-in-functions/string/left.md)
* [ListReduce](/boxlang-language/reference/built-in-functions/string/listreduce.md)
* [LJustify](/boxlang-language/reference/built-in-functions/string/ljustify.md)
* [LTrim](/boxlang-language/reference/built-in-functions/string/ltrim.md)
* [Mid](/boxlang-language/reference/built-in-functions/string/mid.md)
* [ParagraphFormat](/boxlang-language/reference/built-in-functions/string/paragraphformat.md)
* [PascalCase](/boxlang-language/reference/built-in-functions/string/pascalcase.md)
* [QueryStringToStruct](/boxlang-language/reference/built-in-functions/string/querystringtostruct.md)
* [ReEscape](/boxlang-language/reference/built-in-functions/string/reescape.md)
* [reFindNoCase](/boxlang-language/reference/built-in-functions/string/refindnocase.md)
* [ReMatch](/boxlang-language/reference/built-in-functions/string/rematch.md)
* [reMatchNoCase](/boxlang-language/reference/built-in-functions/string/rematchnocase.md)
* [RemoveChars](/boxlang-language/reference/built-in-functions/string/removechars.md)
* [RepeatString](/boxlang-language/reference/built-in-functions/string/repeatstring.md)
* [Replace](/boxlang-language/reference/built-in-functions/string/replace.md)
* [ReplaceList](/boxlang-language/reference/built-in-functions/string/replacelist.md)
* [ReplaceListNoCase](/boxlang-language/reference/built-in-functions/string/replacelistnocase.md)
* [ReplaceNoCase](/boxlang-language/reference/built-in-functions/string/replacenocase.md)
* [ReReplace](/boxlang-language/reference/built-in-functions/string/rereplace.md)
* [reReplaceNoCase](/boxlang-language/reference/built-in-functions/string/rereplacenocase.md)
* [Reverse](/boxlang-language/reference/built-in-functions/string/reverse.md)
* [Right](/boxlang-language/reference/built-in-functions/string/right.md)
* [RJustify](/boxlang-language/reference/built-in-functions/string/rjustify.md)
* [RTrim](/boxlang-language/reference/built-in-functions/string/rtrim.md)
* [Slugify](/boxlang-language/reference/built-in-functions/string/slugify.md)
* [SnakeCase](/boxlang-language/reference/built-in-functions/string/snakecase.md)
* [SpanExcluding](/boxlang-language/reference/built-in-functions/string/spanexcluding.md)
* [SpanIncluding](/boxlang-language/reference/built-in-functions/string/spanincluding.md)
* [SQLPrettify](/boxlang-language/reference/built-in-functions/string/sqlprettify.md)
* [StringBind](/boxlang-language/reference/built-in-functions/string/stringbind.md)
* [StringEach](/boxlang-language/reference/built-in-functions/string/stringeach.md)
* [StringEvery](/boxlang-language/reference/built-in-functions/string/stringevery.md)
* [StringFilter](/boxlang-language/reference/built-in-functions/string/stringfilter.md)
* [StringMap](/boxlang-language/reference/built-in-functions/string/stringmap.md)
* [StringReduce](/boxlang-language/reference/built-in-functions/string/stringreduce.md)
* [StringReduceRight](/boxlang-language/reference/built-in-functions/string/stringreduceright.md)
* [StringSome](/boxlang-language/reference/built-in-functions/string/stringsome.md)
* [StringSort](/boxlang-language/reference/built-in-functions/string/stringsort.md)
* [StripCR](/boxlang-language/reference/built-in-functions/string/stripcr.md)
* [Trim](/boxlang-language/reference/built-in-functions/string/trim.md)
* [TrueFalseFormat](/boxlang-language/reference/built-in-functions/string/truefalseformat.md)
* [UCase](/boxlang-language/reference/built-in-functions/string/ucase.md)
* [UCFirst](/boxlang-language/reference/built-in-functions/string/ucfirst.md)
* [Val](/boxlang-language/reference/built-in-functions/string/val.md)
* [Wrap](/boxlang-language/reference/built-in-functions/string/wrap.md)
* [YesNoFormat](/boxlang-language/reference/built-in-functions/string/yesnoformat.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/string/refind.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
