Regular expressions
in LiveCode.
Logo sunny-tdz sunnYrex
a LiveCode library.

LiveCode & Regex

sunnYrex provides a much better user experience for searching, transforming or extracting complex chunks of datas using regular expressions . With sunnYrex you code in a couple of lines around a regex what would require multiple lines of code otherwise. sunnYrex manages all the tricky details for you around matchText(), matchChunk(), filter and replaceText liveCode functions.

alternate Regex or WildCard patterns. Users can switch to wildcard or regex patterns for all sunnYrex functions.


regex abstract patterns
Regular expressions in language theory and regular expressions in practice are different beasts... since regular expressions don't have niceties such as back references , forward references etc.



version 1.14 - 17 Dec 2019 version 1.14 - 17 Dec 2019

sunnYrex Documentation

Get a lifetime license with 1 year of updates.

Understand your data and be more productive!

Choose Regex or WildCard patterns.

All matches available in one array

Back references in replacement string

Callback handler in replacement string

Smart replacement string

The replacement string in LiveCode replaceText() function has been replaced with an even smarter one. The latter accepts back references , LiveCode handler or function callbacks with optional back references as parameters. An extract() function has been added to collect the captured groups contents - faster than the replace() function.

Read the documentation for some code samples

Use cases

Translate Javascript to LiveCode

Find below a subset of a javascript code translated to LiveCode. This job was done in less than an hour!

# Javascript:
T = T.replace(/([mnq])([iou])([-])([o])([bctvz])([-])([oae])/g,'$1$2$4-$5$7');
T = T.replace(/([ ])([bcdfghlmnpqrstvz])([i])([eauio])/g , '$1$2$3-$4');
T = T.replace(/([ui])([-])([aeo])([-])([iu])/g , '$1$3-$5');
T = T.replace(/([aeoiu])([aouie])([iu])/g , '$1-$2$3);
  < /skipped few more lines... >

# Translated to LiveCode:
sunnYreplace(T,"([bcd])([aeu])([-])([o])([bctvz])([-])([oae])", "\1\2\4-\5\7",T)
sunnYreplace(T,"([ ])([bcdfghlmnpqrstvz])([i])([eauio])", "\1\2\3-\4",T)
sunnYreplace(T,"([ui])([-])([aeo])([-])([iu])", "\1\3-\5",T)
sunnYreplace(T,"([aeoiu])([aouie])([iu])", "\1-\2\3",T)

ASCII German-Hebraic Bible to Unicode

Convert an old metacard stack with several thousand cards. The entired text is encoded in ASCII, with specific fonts to render Hebraic or special German characters. The goal was to transform all ASCII texts to Unicode in order to render them compatible with LiveCode version 7+. Below is a sample of generated text in Unicode.

Ps 6
3 Herr! Sei mir gnädig! / Ich vergehe, Herr! / Verschone mich! / Erschüttert ist mein Leib.  * (Grünewald)
3 Sei mir gnädig, Jahwe! Denn ich bin dahingewelkt; heile mich, Jahwe! Denn meine Gebeine sind bestürzt. (ELB)
3 ἐλέησόν με, κύριε, ὅτι ἀσϑενής εἰμι: ἴασαί με, κύριε, ὅτι ἐταράχϑη τὰ ὀστᾶ μου,  (LXX)
3 Miserere mei, Domine, quoniam infirmus sum; sana me, Domine, quoniam conturbata sunt ossa mea. (NovaVulgata)

Parse Bible - build hyperlinks

Translate thousands of biblic references to htmlText links which refer to text fields from other stacks. This job was done in three days!

According to Matthew and Mark, Jesus’ central proclamation is that the kingdom of God “has come near” (Matthew 4:17; 10:7; Mark 1:14-15; see also Luke 10:8-11). The Miracle Worker Jesus performs many miracles, such as healing people who are ill or disabled (for example, Matthew 8:1-4; Mark 5:25-34; Luke 7:1-10; John 5:1-9); feeding a multitude with a handful of loaves and a few fish (Matthew 14:13-21; 15:32-39; Mark 6:34-44; 8:1-10; Luke 9:10-17; John 6:1-15); and walking across the Sea of Galilee (Matthew 14:22-33; Mark 6:45-52; John 6:16-21). In Matthew, Mark, and Luke, Jesus exorcises many people who are possessed by demons (for example, Mark 5:1-13). These exorcisms are said to be a sign that the kingdom or reign of God is breaking into the human world (Matthew 12:28; Luke 11:20). The Teacher In Matthew, Mark, and Luke,

The regex for this transformation was 3571 chars long and the whole process took a couple of seconds. I've coded a DSL to build the regex. For this presentation, I've changed the links to an alert() showing the link number.

According to Matthew and Mark, Jesus’ central proclamation is that the kingdom of God “has come near” (Matthew 4:17; 10:7; Mark 1:14-15; see also Luke 10:8-11).

The Miracle Worker
Jesus performs many miracles, such as healing people who are ill or disabled (for example, Matthew 8:1-4; Mark 5:25-34; Luke 7:1-10; John 5:1-9); feeding a multitude with a handful of loaves and a few fish (Matthew 14:13-21; 15:32-39; Mark 6:34-44; 8:1-10; Luke 9:10-17; John 6:1-15); and walking across the Sea of Galilee (Matthew 14:22-33; Mark 6:45-52; John 6:16-21). In Matthew, Mark, and Luke, Jesus exorcises many people who are possessed by demons (for example, Mark 5:1-13). These exorcisms are said to be a sign that the kingdom or reign of God is breaking into the human world (Matthew 12:28; Luke 11:20).

The Teacher
In Matthew, Mark, and Luke,

System Requirements

Platforms: All.

LiveCode commercial editions version 8.0 or up.