Page MenuHomeFeedback Tracker

[Feature Request] Regex commands
Closed, ResolvedPublic

Description

Find: Two commands, one with array return, and one with boolean:

string regexFind [regex, startFrom, returnAll];

string: STRING: the string to search in
regex: STRING: regular expression
startFrom: NUMBER: the start index
returnAll: BOOL: (optional) return all results
Returns: ARRAY: Array of string-number pairs in format: [[match1, position1], [match2, position2] , ...] (if returnAll is false, only the first match is returned). If no match is found or there is an error, an empty array is returned.

string regexMatch regex

string: STRING: the string to search in
regex: STRING: regular expression
Returns: BOOL: whether a match was found

Replace: replace all found matches:

string regexReplace [regex, replace]

string: STRING: the string to search in
regex: STRING: regular expression
replace: STRING: regular expression
Returns: STRING: the string after replacing all found matches (or original string in case of error)

For single replace, one can use find and replace together:

_text = "Hello world!";
_firstMatch = _text regexFind ["\w+", 0];
_firstMatch params ["_match", "_pos"];
_newText = (_text select [0, _pos]) + (_match regexReplace ["\w+", "blabla"]) + (_text select [_pos + count _match]);

Details

Severity
Feature
Resolution
Open
Reproducibility
N/A
Operating System
Windows 7
Category
Scripting

Event Timeline

Leopard20 updated the task description. (Show Details)
Leopard20 updated the task description. (Show Details)Mar 17 2021, 5:45 PM
Leopard20 updated the task description. (Show Details)
Leopard20 updated the task description. (Show Details)
R3vo added a subscriber: R3vo.Mar 17 2021, 5:48 PM
Leopard20 updated the task description. (Show Details)Mar 17 2021, 5:55 PM
h- added a subscriber: h-.Mar 18 2021, 1:41 PM
dedmen claimed this task.Apr 20 2021, 5:05 PM
dedmen changed the task status from New to Assigned.
dedmen set Ref Ticket to AIII-54075.
dedmen added a comment.May 6 2021, 9:22 PM

regexFind had issues, changing return syntax

"test is a cat test is a cat" regexFind ["(.*?) is a ([\S]*)"]

->

[["test is a cat", 0, ["test", 0], ["cat", 10]], [" test is a cat", 14, [" test", 14], ["cat", 24]]]

dedmen closed this task as Resolved.May 27 2021, 10:33 AM

Done in 2.06