0

我有这一段(可能我有不止一段)

=> "On the server side,\n\nmy EJB3 application uses Spring for configuring all sorts of things. So,\n\nmy EJBs all look up various ApplicationContexts and use them as a sort of\r\nwell, I was going to say poor man's JNDI, but the reality is that JNDI in the J2EE environment is really a poor man's Spring. :-)\n\nOn the GUI side,\n\nI use it instead of resource injection to get access to my EJBs.\n\nThat lets me test the GUI component with simple pojos.\n\nHope that helps."

irb,我将其分配到x

x = %q{On the server side,\n\nmy EJB3 application uses Spring for configuring all sorts of things. So,\n\nmy EJBs all look up various ApplicationContexts and use them as a sort of\r\nwell, I was going to say poor man's JNDI, but the reality is that JNDI in the J2EE environment is really a poor man's Spring. :-)\n\nOn the GUI side,\n\nI use it instead of resource injection to get access to my EJBs. \n\nThat lets me test the GUI component with simple pojos.\n\nHope that helps.}

根据回车符(\r)和换行符(\n),我只需要上面段落中的这些细节,任何想法我该怎么做?

my EJB3 application uses Spring for configuring all sorts of things. So,...my EJBs all look up various ApplicationContexts and use them as a sort of...I use it instead of resource injection to get access to my EJBs....

非常简单的方法-假设我有a\nabc\r\nd\r\nab\neba并且搜索关键字是b,我只需要abcabeba

4

2 回答 2

1

我不知道<em>\1</em>这里的相关性如何,但我想你可能想要这个。

x.scan(/.*ejb.*/i).join("...")

请注意,正则表达式处于单行模式。

或者,如果您在 Linux 上执行此操作,并且仍然需要处理 (not only \nbut also) \r,那么这可能更安全:

x.scan(/[^\n\r]*ejb[^\n\r]*/i).join("...")
于 2013-04-24T18:14:57.753 回答
0
s = eval("%q{a\nabc\r\nd\r\nab\neba}")
p s.split("\n").select{|x| x.include? 'b'}.join('')
#=>"abcabeba"
于 2013-04-24T18:14:22.797 回答