FindStrRegex

FindStrRegex( value, find, [start], [numResults] )
FindStrRegex( value, find, [start], [numResults] )
FindStrRegex( value, find, [start], [numResults] )
FindStrRegex( value, find, [start], [numResults] )
find_str_regex( value, find, [start], [numResults] )
FindStrRegex( value, find, [start], [numResults] )

Description

The FindStrRegex function returns an array of up to 1,024 objects that describe where the pattern is found in the search string.

Parameters

Argument Type Definition and Requirements

value

The string to search in.

find

The Java-compatible regular expression pattern to find in the value string.

start

Optional - The offset into the search string in characters of where the search should start. The default value, if omitted, is 0 code points. The first position in the string is 0. If the value is less than 0, then start is ignored.

Although we mention characters, technically, we are talking about code points. In Unicode, a code point is usually, but not always, a character. Code points can sometimes represent single characters, but can also represent formatting and other non-alphanumeric characters.

For example, the character é can be the single character "e" that includes an acute accent (U+00E9), or it could be displayed as a single character but be composed of an "e" (U+0065) and a "combining" acute accent (U+0301). Visually, you cannot distinguish between the two.

numResults

Optional - The number of matches to find in the search string. The default is 1,024 and the maximum is 1,024.

Returns

An array of objects where each object contains the details of a match, including the start position, end position, and the sub-string that was matched.

Examples

  1. The following query searches the string ABC abc ABC for the pattern [Bb], which matches the letter B or the letter b. The result is an array of the three matches that exist, with each match reporting the start and end positions of the match, and the actual sub-string that matched:

    Value result = await client.Query(
        FindStrRegex("ABC abc ABC", "[Bb]")
    );
    
    Console.WriteLine(result);
    Arr(ObjectV(start: LongV(1),end: LongV(1),data: StringV(B)), ObjectV(start: LongV(5),end: LongV(5),data: StringV(b)), ObjectV(start: LongV(9),end: LongV(9),data: StringV(B)))
    result, err := client.Query(
    	f.FindStrRegex("ABC abc ABC", "[Bb]"))
    
    if err != nil {
    	fmt.Fprintln(os.Stderr, err)
    } else {
    	fmt.Println(result)
    }
    [map[data:B end:1 start:1] map[data:b end:5 start:5] map[data:B end:9 start:9]]
    System.out.println(
        client.query(
            FindStrRegex("ABC abc ABC", "[Bb]")
        ).get());
    [{start: 1, end: 1, data: "B"}, {start: 5, end: 5, data: "b"}, {start: 9, end: 9, data: "B"}]
    client.query(
      q.FindStrRegex('ABC abc ABC', '[Bb]')
    )
    .then((ret) => console.log(ret))
    .catch((err) => console.error('Error: %s', err))
    [
      { start: 1, end: 1, data: 'B' },
      { start: 5, end: 5, data: 'b' },
      { start: 9, end: 9, data: 'B' }
    ]
    result = client.query(
      q.find_str_regex("ABC abc ABC", "[Bb]")
    )
    print(result)
    [{'start': 1, 'end': 1, 'data': 'B'}, {'start': 5, 'end': 5, 'data': 'b'}, {'start': 9, 'end': 9, 'data': 'B'}]
    Not available in this language yet.
  2. The following query uses the same value string and find pattern as the previous example, but it also specifies a start position. The start position is far enough into the value string that there are only two matches in the result:

    Value result = await client.Query(
        FindStrRegex("ABC abc ABC", "[Bb]", 5)
    );
    
    Console.WriteLine(result);
    Arr(ObjectV(start: LongV(5),end: LongV(5),data: StringV(b)), ObjectV(start: LongV(9),end: LongV(9),data: StringV(B)))
    result, err := client.Query(
    	f.FindStrRegex("ABC abc ABC", "[Bb]", f.Start(5)))
    
    if err != nil {
    	fmt.Fprintln(os.Stderr, err)
    } else {
    	fmt.Println(result)
    }
    [map[data:b end:5 start:5] map[data:B end:9 start:9]]
    System.out.println(
        client.query(
            FindStrRegex("ABC abc ABC", "[Bb]", 5)
        ).get());
    [{start: 5, end: 5, data: "b"}, {start: 9, end: 9, data: "B"}]
    client.query(
      q.FindStrRegex('ABC abc ABC', '[Bb]', 3)
    )
    .then((ret) => console.log(ret))
    .catch((err) => console.error('Error: %s', err))
    [ { start: 5, end: 5, data: 'b' }, { start: 9, end: 9, data: 'B' } ]
    result = client.query(
      q.find_str_regex("ABC abc ABC", "[Bb]", 5)
    )
    print(result)
    [{'start': 5, 'end': 5, 'data': 'b'}, {'start': 9, 'end': 9, 'data': 'B'}]
    println(Await.result(
        client.query(
            FindStrRegex("ABC abc ABC", "[Bb]", 5)
        ),
        5.seconds
    ))
    [{start: 5, end: 5, data: "b"}, {start: 9, end: 9, data: "B"}]
  3. The following query uses the same value string, find pattern, and start position as the previous example, but it also specifies a numResults limit. The limit restricts the number of results to one:

    Value result = await client.Query(
        FindStrRegex("ABC abc ABC", "[Bb]", 5, 1)
    );
    
    Console.WriteLine(result);
    Arr(ObjectV(start: LongV(5),end: LongV(5),data: StringV(b)))
    result, err := client.Query(
    	f.FindStrRegex("ABC abc ABC", "[Bb]", f.Start(5), f.NumResults(1)))
    
    if err != nil {
    	fmt.Fprintln(os.Stderr, err)
    } else {
    	fmt.Println(result)
    }
    [map[data:b end:5 start:5]]
    System.out.println(
        client.query(
            FindStrRegex("ABC abc ABC", "[Bb]", 5, 1)
        ).get());
    [{start: 5, end: 5, data: "b"}]
    client.query(
      q.FindStrRegex('ABC abc ABC', '[Bb]', 3, 1)
    )
    .then((ret) => console.log(ret))
    .catch((err) => console.error('Error: %s', err))
    [ { start: 5, end: 5, data: 'b' } ]
    result = client.query(
      q.find_str_regex("ABC abc ABC", "[Bb]", 5, 1)
    )
    print(result)
    [{'start': 5, 'end': 5, 'data': 'b'}]
    println(Await.result(
        client.query(
            FindStrRegex("ABC abc ABC", "[Bb]", 5, 1)
        ),
        5.seconds
    ))
    [{start: 5, end: 5, data: "b"}]

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's Discourse forums or email docs@fauna.com

Thank you for your feedback!