[FREE] Extension Xreg V1.2- PCRE regular expressions for App Inventor!

New title:
[FREE] Extension Xreg V1.5- Java regular expressions for App Inventor.
Version V1.5 adds features to version V1.4.
Download New Version V1.5
Xreg.aix (9.5 KB)

News features in "replacement" string of RegexReplace block:
The replacement string can contain special sequences, defined after each match, which the function interprets in the following way:

Sequence Description
$0 The sequence $0 denotes the complete match. The function first replaces each occurrence of $0 in replacement with the full match, then replaces the full match in the original text with replacement.
  ➤ RegexpReplace("-123-", "\d", "$0$0") returns the text "-112233-".
$1,...,$99 The sequence $ followed by a digit or two digits will be replaced in the replacement string by the specified number capture group.
The parser considers the two digits following '$', if it finds two. If a capture group with this number exists, the sequence "$dd" will be replaced by the capture group n°dd, and if no group has this number, the analyzer repeats the same test with "$d" and will add the second digit behind group n°d.
You can create up to 99 capture groups in Java.
  ➤ RegexpReplace("06/10/2023", "(\d\d)/(\d\d)/(\d\d\d\d)", "$0 -> $3-$2-$1") returns the text "06/10/2023 -> 2023-10-06".
  ➤ RegexpReplace("123", "(\d)", "$14") returns the text "142434" because the group n°14 does not exist so $14 is interpreted as $1 followed by the number 4 for all three occurrences.
  ➤ RegexpReplace("345789a", "(((3)(4))(5))((7)(?8))(9)(a)", "$10") returns "a" because group 10 exists (count the opening parentheses).
  ➤ RegexpReplace("345789a", "(((3)(4))(5))((7)(?8))(9)(a)", "$12") returns "3452" because group 12 does not exist so the function adopts the interpretation "$1 followed by the number 2".
${1}2 Represents group n°1 followed by the number 2. If capture group n°12 does not exist, it is the same to write $12, but if it exists, the braces are used to force a rather than another.
  ➤ RegexpReplace("345789a", "(((3)(4))(5))((7)(?8))(9)(a)", "${1}0") returns "3450", group n°1 followed by '0'.
${name} The sequence ${name} will be replaced in the replacement string by the capture group named "name". This method of referencing groups is especially useful when there are many capture groups to manage.
  ➤ RegexpReplace("06/10/2023", "(?<day>\d{2})/(?<month>\d{2})/(?<year>\d{4}) ", "${year}-${month}-${day}") returns the text "2023-10-06".
In addition to the previous sequences supported by Java, RegexpReplace() recognizes the following syntaxes:
$Ln, $L{n}, $L{name} The letter 'L' or 'l' (Lower) inserted between '$' and the group number or name will make the group lowercase.
  ➤ RegexpReplace("App Inventor", ".+", "$L0") returns the text "app inventor": the full text in lower case.
$Un, $U{n}, $U{name} The letter 'U' or 'u' (Upper) inserted between '$' and the group number or name will capitalize the group.
  ➤ RegexpReplace("Le Corbeau et le Renard", "(.)e", "$u1e") returns "Le CorBeau et le Renard": all characters immediately before the letter e are capitalized, when they have a capital letter!
$Tn, $T{n}, $T{name} The letter 'T' or 't' (Title) inserted between '$' and the number or name of the group will capitalize the first letter of each word in the group.
  ➤ RegexpReplace("app inventor", "(.+)", "$t1") returns "App Inventor".
2 Likes