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

by Jan 29, 2018


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.!#$%&'*+/=?^_`{|}~-]+@[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.