The goal of this class is to reduce the complexity of code to use Regex in 4D.
var $regex : cs.regex
$regex:=cs.regex.new("Hello world, the world is wonderful but the world is in danger"; "Hello (world)")
var $match : Boolean
$match:=$regex.match() // = True
var $c : Collection
$c:=$regex.extract() // = [ "Hello world", "world" ]
$c:=$regex.extract(1) // = [ "world"]
var $result : Text
$result:=$regex.substitute("Vincent") // = "Vincent, the world is wonderful but the world is in danger"
The complete class documentation is available here and is also displayed in the Explorer documentation panel.
The test_regex method will help you learn how to use it.
This repository is compatible with the Project dependencies feature. So you can simply integrate this component into your project by selecting Design
> Project dependencies
and adding vdelachaux/regex-with-classes
as the repository address in the dedicated dialog box. This way, you can benefit from updates over time.
The published namespace is "rgx", so the class instantiation in your project will therefore be:
$regex:=cs.rgx.regex.new()
Copy into your database folder:
- The
regex.4dm
file from this repository to the~/Project/Sources/Classes/
folder - The
regex.md
file from this repository to the~/Documentation/Classes/
folder
The class instantiation will therefore be:
$regex:=cs.regex.new()
This class will be augmented according to my needs but I strongly encouraged you to enrich this project through pull request. This can only benefit the 4D developer community
📌 This code is an evolution of the regex component.
- RegexLab component
- macOS RegExRX. An application I use regularly to test my Regex. It allows you to copy them, once finalized in a format compatible with 4D's code editor, and even to copy the FR or US code like this:
ARRAY LONGINT($rxPositions;0)
ARRAY LONGINT($rxLengths;0)
$rxPattern:="(?mi-s)world"
$rxMatch:=Match regex($rxPattern;$sourceText;1;$rxPositions;$rxLengths)
Enjoy the 4th dimension