How to use verbatin String in managed c++

Hari Pranesh 166 Reputation points
2023-01-03T08:12:34.25+00:00

I'm working with c# regex and got the expected result

var match = Regex.Match(sub, @"\w{5}-\w{5}-\w{5}-\w{5}-\w{5}");

So now I'm working with the same code with managed c++, now Im getting error in Regex.Match().

Match m = Regex::Match(number[i], "\w{5} - \w{5} - \w{5} - \w{5} - \w{5}");

but I'm getting the following error "no suitable user-defined conversion from "System::Text::RegularExpressions::Match ^" to "System::Text::RegularExpressions::Match" exists"

I also used raw string for the regex pattern, still the issue is resolved

Match m = Regex::Match(number[i], R"~(\w{5} - \w{5} - \w{5} - \w{5} - \w{5})~");

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
6,960 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
2,625 questions
No comments
{count} votes

Accepted answer
  1. Viorel 82,661 Reputation points
    2023-01-03T09:03:12.4+00:00

    Try:

    ā€ƒMatch ^m = Regex::Match( number[i], R"(\w{5}-\w{5}-\w{5}-\w{5}-\w{5})" );

    No comments

0 additional answers

Sort by: Most helpful