I
I
IWakd2020-05-11 10:48:03
C++ / C#
IWakd, 2020-05-11 10:48:03

How to make the correct output of the modified regular string?

There is a code:

#include<iostream>
#include<string>
#include<regex>
using namespace std;
int main()
{
    string str;         //объявление строки для изменения
    cout<<"Enter string : ";getline(cin, str);       //ввод строки
    regex regular("(www.\\w+\\.\\w+)|(http""s?://""\\w+\\.\\w+)|(^[email protected]+\\..+$)");   
    cout<<"Modified string : "<<regex_replace(str, regular, " ***** ")<<endl;         //вывод измененной строки
}

The output is just asterisks, it should change links like www.expamp.com,http(s)://example.com,
and emails to stars.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2020-05-11
@jcmvbkbc

The output is just asterisks, it should change links like www.expamp.com, http(s)://example.com, and emails to stars.

Well, so what? This regular expression changes the first two classes, in e-mail addresses the last .+$one matches the string to the end. As written, it works.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question