Skip to content

PICARD-3068: Document group parameter for $rsearch (PICARD-3072) #230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion functions/func_rsearch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$rsearch
========

| Usage: **$rsearch(text,pattern)**
| Usage: **$rsearch(text,pattern[,group])**
| Category: text

**Description:**
Expand All @@ -21,6 +21,13 @@ If more than one marked subexpression is defined and not all are matched, an emp
be returned. If no subexpression is specified, then the pattern captured by the whole search
expression will be returned.

If the optional ``group`` parameter is not provided or is empty, return the first
capture group which matched something (including the empty string) or the
entire match.

If ``group`` is an integer, return the capture group in the position matching this integer.
Otherwise, return the capture group named ``group``, sans surrounding whitespace.

.. note::

When entering regular expressions into Picard scripts you have to escape a backslash "\\",
Expand All @@ -29,6 +36,10 @@ expression will be returned.
a backslash before the character to be escaped. For example, the regular expression
``^\s*([0-9,\.]*)$`` would have to be entered as ``^\\s*\([0-9\,\\.]*\)\$``.

.. note::

The ``group`` argument was added in Picard v2.14.

**Example:**

The following statements will return the values indicated:
Expand All @@ -44,3 +55,5 @@ The following statements will return the values indicated:
$rsearch(test,\(e\).*\(s\)) ==> "e"
$rsearch(test,\(e\).*x) ==> ""
$rsearch(test,\(e\).*\(x\)) ==> ""
$rsearch(disc: 3,\(\\w+\): \(\\d+\),1) ==> "disc"
$rsearch(disc: 3,\(\\w+\): \(\\d+\),2) ==> "3"