English 中文(简体)
这一替代标准是什么?
原标题:What would the correct regex be for this replacement?
  • 时间:2011-01-20 03:14:52
  •  标签:
  • regex

这是半个问题,半个是小qui,因为小.将位于,而且难以创造。

如果我自己这样做(是因为我实际上需要使用<>>>),我将撰写一份文件,而不是一份文件,尽管我知道可以在此案中使用reg,而且我认为,也许有一些StackOverflow的编码人喜欢质疑。

作为“归还”,我把问题搁置了7天,届时将有一个150张“<>/>荣誉”的<座右铭,以正确的答案归属此人。 我知道,回答者可能已经过去了;3K级的名誉,但反响却令人厌恶,我假定:

The regex will have to turn:

[DllImport(EngineDll)]
public static extern int Graphics(int width, int height, int depth = default(int), int hertz = 60, int flags = (int)(GraphicsBufferType.Back | GraphicsBufferType.Depth));

Into:

public static int Graphics(int width, int height, int depth = default(int), int hertz = 60, int flags = (int)(GraphicsBufferType.Back | GraphicsBufferType.Depth))
{
    if (Engine.ThreadSafe)
    {
        lock (typeof(Dll))
        {
            return Dll.Graphics(width, height, depth, hertz, flags);
        }
    }
    else
    {
        return Dll.Graphics(width, height, depth, hertz, flags);
    }
}

由于在上不需要“”多线,如果你发现可以比较容易地划分:

public static int Graphics(int width, int height, int depth = default(int), int hertz = 60, int flags = (int)(GraphicsBufferType.Back | GraphicsBufferType.Depth)) { if (Engine.ThreadSafe) { lock (typeof(Dll)) { return Dll.Graphics(width, height, depth, hertz, flags); } } else { return Dll.Graphics(width, height, depth, hertz, flags); } }

现在,如果足够明显的话,变数是返回类型、方法名称、参数类型、参数名称、参数是否具有违约值,以及在这种情况下是违约数值。 该职能可能是无效的,在这种情况下,不应提出返回声明。

On request: Second input-output:

[DllImport(EngineDll)]
public static extern void EndRender();

Output:

public static void EndRender()
{
    if (Engine.ThreadSafe)
    {
        lock (typeof(Dll))
        {
            Dll.EndRender();
        }
    }
    else
    {
        Dll.EndRender();
    }
}

另有1人接受了。

:

Note to all who may comment I m Just lazy: Change question.

最佳回答

你能够用真正的定期表述来做到这一点,因为你需要能够处理缺省值中的平衡父母。 尽管如此,还有传票,允许你处理此类事情,从而让滚动球:

s/[DllImport(EngineDll)]
public static extern #boilerplate
  (?<method> #capturing group for the method signature
  (?<return>w+) #Method return type
  (?<name>w+)( #Method name
  (?<parameter>w+ #parameter type
   (?<parname>w+) #parameter name
   (= (?&DEFAULTVALUEREGEX))? #optional default value
   (?{$params = $+{parname}}) #Ok, so this isn t even pretending to be a regex 
                              # anymore. If anyone has any better ideas...
  )(?:, #parameter seperator
   w+ (?<par>w+) (= (?&DEFAULTVALUEREGEX))?
   (?{ $params .= ", " . $+{par}}))* # more parameters
   )); # boilerplate
  /
  public static $+{method} { if (Engine.ThreadSafe) { lock (typeof(Dll)) { return Dll.$+{name}($params); } } else { return Dll.$+{name}($params); }}
  /x

我的口号包括“DEFAULTVALUEREGEX”的定义,因为这一定义基本上要求你将任何具有法律效力的C#表述混为一谈,而这种表述将足以掩盖逻辑的其余部分。 它还使用<代码>(?{代码})的构造,使人特别怀疑这甚至是否是一种定期表述。 而且,我只试过了,因为我 like了,而且真的bri弄了(一只仍然有效的C#的楼梯上弹)。

如果任何人有任何改进,就会感到可以随意 ,这首先会给妇女委员会造成污点。

问题回答

因此,这有什么错误?

s/.*/public static int Graphics(int width, int height, int depth = default(int), int hertz = 60, int flags = (int)(GraphicsBufferType.Back | GraphicsBufferType.Depth)) { if (Engine.ThreadSafe) { lock (typeof(Dll)) { return Dll.Graphics(width, height, depth, hertz, flags); } } else { return Dll.Graphics(width, height, depth, hertz, flags); } }/;

既然这(可能)是你所想的,那么就必须进行另一种转变,即同样的管理者也必须这样做——否则我提供的东西就足以胜任工作。





相关问题
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" ...