Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!

On iPhone X(iOS11.2), use Regular Expressions library.

Author: h.mohri


The 35th Developer camp will be held in Japan on March 15, 2018.
The venue is Tokyo Akihabara UDX GALLERY NEXT.



C++Builder 10.2.2 is one of the merits of being able to use RTL and STL.
For RTL, the classes on Regular expressions are TRegExTPerlRegEx.
But, since std::regex of STL can also be used, I set the target device to iOS this time and tried it.

I tried four patterns.The pattern is numbers, hiragana-Japanese, ASCII and e-mail.


C++Builder 10.2.2 code

#include <string>
#include <regex>
#include <functional>

#include <vector>
#include <tuple>

void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
    std::vector<std::tuple<std::wstring, std::wstring> > v1{
        //When you want to match numbers.
        {L"\\d+", L"regex_match(\"\\d+\",%s)"},
        //When you want to match Hiragana-Japanese.
        {L"^[\u3040-\u309F]+$", L"regex_match(\"^[\u3040-\u309F]+$\",%s)"},
        //When you want to match ASCII Code.
        {L"^[\x20-\x7E]+$", L"regex_match(\"^[\x20-\x7E]+$\",%s)"},
        //Determine whether the wstring is in E-mail format.
        {L"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-][email protected][a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$", L"regex_match(E-Mail,%s)"}

    std::function<std::wstring(UnicodeString)> str_towstr{[](UnicodeString linp)
            std::wstring out;
            for (int i=0; i < linp.Length(); i++) {
               #ifndef _WIN64
                out +=linp[i];
               #else /* _WIN64 */
                out +=linp[i+1];
            return out;

    //It was selected in the ComboBox1, the content you want to match.
    std::wregex wregex1(std::get<0>(v1[ComboBox1->ItemIndex]).c_str());

    //The string you want to match, and assigned to the wstring.
    std::wstring in_str = str_towstr(Edit1->Text);

    UnicodeString l_value = Format(std::get<1>(v1[ComboBox1->ItemIndex]).c_str(), ARRAYOFCONST((Edit1->Text)) );
    //It is judged here. Use regex_match.
    if (std::regex_match(in_str, wregex1))
        //If the regex_match was successful.
        Memo1->Lines->Append("Successful " + l_value);
        Edit1->Text = L"";
        //If the regex_match failed.
        Memo1->Lines->Append("NO " + l_value);

Select a pattern in ComboBox1, enter a character string in Edit1, and tap SpeedButton1.
If a pattern match is found, Successful is displayed in Memo1.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Related posts

The Future Of Desktop Apps Is Native Code


Solve MILLIONS of Unknowns In Equations - We Show You How!


C++Builder Optimization Guide with TwineCompile

C++CodeIDERAD Studio

LearnCPlusPlus.org :: Object-Oriented Programming, Structs, Classes, Objects And More

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.