【问题标题】:Converting snippet from PHP - how to "convert" preg_replace从 PHP 转换代码段 - 如何“转换” preg_replace
【发布时间】:2013-08-11 00:07:23
【问题描述】:

我正在尝试翻译以下代码。看起来很简单,但我不知道如何在 c# 中实现等效的 preg_replace

$sentence = trim(preg_replace('/[¿?¡!«»}،\]\/()[{,、/.,;":0-9]/', ' ', $_GET["sentence"]));
$word = explode(" ", $sentence );
foreach($word as $k => $v) {
    echo $v."; ";
};

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    我贡献了这个答案。也许它对你有用。 https://stackoverflow.com/a/18132398/278976

    除了教你如何更好地使用正则表达式之外,它还会为许多不同的语言生成源代码。您还可以从不同的转义模式复制,以进行您要求的精确转换。

    使用 regexbuddy 2.3.0,我得到:

    string ResultString = null;
    try {
        ResultString = Regex.Replace(SubjectString, "[¿?¡!«»}،\\]/()[{,、/.,;\":0-9]", "");
    } catch (ArgumentException ex) {
        // Syntax error in the regular expression
    }
    

    【讨论】:

      猜你喜欢
      • 2019-07-18
      • 2016-05-18
      • 1970-01-01
      • 1970-01-01
      • 2021-09-05
      • 1970-01-01
      • 1970-01-01
      • 2020-09-02
      • 2019-05-20
      相关资源
      最近更新 更多