如何使用正则表达式作为替换

时间:2014-04-01 19:47:31

标签: javascript python regex string pcre

我有一个替换字符串:

  

********is******ri****f******s**d******s****du****?

和搜索模式:

([y\s]|[wh]|[apl]|[oo]|[mb])*

和替换模式:

*$2*

是否可以找出原始字符串是什么,或使用替换模式来反转它?

1 个答案:

答案 0 :(得分:0)

由于正则表达式中有许多替代方法,如果要反转操作,则不会只有一个结果,因为正则表达式包含以下替代方法:

1st Alternative: [y\s]
[y\s] match a single character present in the list below
    y the literal character y (case sensitive)
    \s match any white space character [\r\n\t\f ]
2nd Alternative: [wh]
[wh] match a single character present in the list below
    wh a single character in the list wh literally (case sensitive)
3rd Alternative: [apl]
[apl] match a single character present in the list below
    apl a single character in the list apl literally (case sensitive)
4th Alternative: [oo]
[oo] match a single character present in the list below
    oo the literal character o (case sensitive)
5th Alternative: [mb]
[mb] match a single character present in the list below
    mb a single character in the list mb literally (case sensitive)

所以你可以编写一个代码来为你提供所有可能的组合(巨大的负载),但不是一个结果。 希望这有帮助。