【问题标题】:Regular expression for replacing everything after an underscore in a block of the URL用于替换 URL 块中下划线后所有内容的正则表达式
【发布时间】:2013-12-17 20:45:47
【问题描述】:

我有以下人员代码来使用人员代码中的新窗口逻辑在新窗口中打开链接。以下 peoplecode 和 java 函数完美地完成了这项工作,直到尝试从已经存在的新窗口打开一个新窗口,这导致正则表达式再添加一个错误的 _newwin。

代码

    Function FgNewWinUrl(&strUrl As string) Returns string;
   Local string &sRegex, &sReplace, &Result;
   /* Declare java object */
   Local JavaObject &jUrl;

   /**
    * Peoplesoft Content types:
    * -------------------------
    * Component: c
    * Script: s
    * External: e
    * Homepage: h
    * Template: t
    * Query: q
    * Worklist: w
    * Navigation: n
    * File: f
   **/

   /* Regex strings */
   /*          psc/psp  Site      Portal    Node      Content Type */
   rem &sRegex = "/(ps[cp])/([^\/]*)?/([^\/]*)?/([^\/]*)?/([csehtqwnf]{1})/";

&sRegex = "/(ps[cp])/([^\/]*)?/([^\/]*)?/([^\/]*)?/([csehtqwnf]{1})/";

rem ^[^_]+(?=_);
   &sReplace = "/$1/$2_newwin/$3/$4/$5/";

   /* Instantiate objects and replace */
   &jUrl = CreateJavaObject("java.lang.String", &strUrl);
   &Result = &jUrl.replaceAll(&sRegex, &sReplace);

   /* Return modified URL */
   Return &Result;
End-Function;

这是我的问题:

我找到了一个正则表达式来查找下划线之前的所有内容。我想将其应用于正则表达式的第二组结果。

请告诉我该怎么做。

【问题讨论】:

    标签: regex peoplesoft


    【解决方案1】:

    试试这个

    &sRegex = "/(ps[cp])/([^\/_]*)?(?:_newwin)?/([^\/]*)?/([^\/]*)?/([csehtqwnf]{1})/";
    

    这会添加一个不包含在组计数中的可选 _newwin。

    如果你必须在第二场比赛中支持下划线,我们需要依靠贪婪......

    【讨论】:

    猜你喜欢
    • 2014-05-03
    • 2011-05-25
    • 2021-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多