English 中文(简体)
是否可定期表达?
原标题:Is this possible with regular expressions?

与此类似:

/[abcd]/[efgh]/

设想将<代码>a替换为e,b with f,c with g.

理想的情况是,这应该是独立的语言。 如果无法做到这一点,我就有一个备用解决办法(由于这一格列斯是由某些法典产生的,我可以就每一种可能的替换作出选择)。

最佳回答

每一升标栏:tr

tr/abcd/efgh/

你们的榜样将做些什么。

问题回答

引文中,<代码>y///的表述只是这样。

该表还载有按附件分列的<代码>tr/的同义词。

同样,用沙尔语, should子也不得不使用reg。

>>> import string
>>> FROM="abcd"
>>> TO="efgh"
>>> table=string.maketrans(FROM,TO)
>>> print "a cold day".translate(table)
e golh hey

如果你真的想做事,某些语言可以表达,作为雕刻的右手,例如(Perl):

(美元)

trick,虽然它,但可能不是你所需要的。

在Zarre,它有可能通过Lambda重新运作。

>>> import re
>>> d={"a":"e","b":"f","c":"g","d":"h"}
>>> re.sub("[abcd]",lambda x:d[x.group(0)],"abcd")
 efgh 

通常,仅仅绘制“a”至“e”图并不真正有用。

在你想要改变一种,b,c,d到例如,在“x”之前,就更有用。 可以通过一个管理机构进行。

>>> re.sub("(?<=x)[abcd]",lambda x:d[x.group(0)],"xaxbxcxdaabbccdd")
>>> xexfxgxhaabbccdd 

除Perl和Adhurc的答复外,还有一架UNIX指挥台。

在PHP中,可以通过在preg_replace上通过阵列来做到这一点。

$outputText = preg_replace($arraySource, $arrayTarget, $inputText);

$arraySource[0] is replaced by $arrayTarget[0]

$arraySource[1] is replaced by $arrayTarget[1]

$arraySource[2] is replaced by $arrayTarget[2]

      .                              .

      .                              .

      .                              .

      .                              .

等等。





相关问题
Uncommon regular expressions [closed]

Recently I discovered two amazing regular expression features: ?: and ?!. I was curious of other neat regex features. So maybe you would like to share some tricky regular expressions.

regex to trap img tag, both versions

I need to remove image tags from text, so both versions of the tag: <img src="" ... ></img> <img src="" ... />

C++, Boost regex, replace value function of matched value?

Specifically, I have an array of strings called val, and want to replace all instances of "%{n}%" in the input with val[n]. More generally, I want the replace value to be a function of the match ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

Is it possible to negate a regular expression search?

I m building a lexical analysis engine in c#. For the most part it is done and works quite well. One of the features of my lexer is that it allows any user to input their own regular expressions. This ...

regex for four-digit numbers (or "default")

I need a regex for four-digit numbers separated by comma ("default" can also be a value). Examples: 6755 3452,8767,9865,8766,3454 7678,9876 1234,9867,6876,9865 default Note: "default" ...

热门标签