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