C # uses a regular whole word matching lookup replacement (Google keyword:c# Regex Whole Word Replace)

Source: Internet
Author: User
Tags lua

When making a gadget that Protoc-gen-lua a local variable into a Table for the Lua file generated for the build, it is necessary to replace the string frequently, but the replace of string is only a mechanical replacement, and all I need is a whole word match replacement, so have to look for the regular way, Google is still very strong, many friends have related solutions, the following a very simple.

static string Replacewholeword (string original, string wordtofind,string replacement, RegexOptions RegexOptions = Regexoptions.none)
        {
            string pattern = String.Format (@ "\b{0}\b", wordtofind);
            string ret = Regex.Replace (original, pattern, replacement, regexoptions);
            return ret;
        }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.