English 中文(简体)
部分定期表达与否
原标题:Partial regular expression match

我经常表示,我正在测试一系列特性。 我不禁要问,是否有办法对投入的定期表述加以匹配,并确定这种表述是否与消耗整个投入缓冲的部分相称? I.e. 输入缓冲器在填表之前就已接近尾声。 我希望执行工作能够决定是否等待更多的投入,或放弃行动。

换言之,我需要确定什么是真实的:

  1. 输入缓冲器的尾声是在reg鱼配对之前到达的。

    E.g. "foo” =~ /^foobar/

  2. 普通表达方式完全吻合

    E.g. "foobar” =~ /^foobar/

  3. 正常表达方式未能达到一致。

    E.g. "fuubar” =~ /^foobar

这些投入没有包装。

问题回答

你们的这种设想是否得到解决? 你们正等待着字面扼杀,例如 f。 如果用户使用部分配对,例如 f,那么你要继续等待。 如果投入是非事项,你想要退出。

如果你在字面上作了说明,我只想写出一个按顺序测试特征的序号。 或

If (input.Length < target.Length && target.StartsWith(input))
   // keep trying

如果你试图与更复杂的定期表达方式相匹配,那么我不知道如何以定期表达的方式这样做。 但我首先要谈谈平台如何执行定期表述。

页: 1

I m not sure if this is your question but.
Regular expressions either match or not. And the expression will match a variable amount of input. So, it can t be determined directly.

然而,如果你认为存在重叠的可能性,则有可能采用聪明缓冲办法来完成同样的事情。

There are many ways to do this.

One way is to match all that does not match via assertions, up until you get the start of a match (but not the full match you seek). These you simple throw away and clear from your buffer. When you get a match you seek, clear the buffer of that data and data before it.

例:/(<Function.*?>>(^<] 你从缓冲地带扔下/cle的那部分是第2组的缓冲。

Another way is if you are matching finite length strings, if you don t match anything in the buffer, you can safely throw away all from the beginning of the buffer to the end of the buffer minus the length of the finite string you are searching for.

Example: Your buffer is 64k in size. You are searching for a string of length 10. It was not found in the buffer. You can safely clear (64k - 10) bytes, retaining the last 10 bytes. Then append (64k-10) bytes to the end of the buffer. Of course you only need a buffer of size 10 bytes, constantly removing/adding 1 character but a larger buffer is more efficient and you could use thresholds to reload more data.

如果你能够创造便于合同/扩大的缓冲,就有更多的缓冲选择。





相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签