正则表达式匹配2个字符之间的所有字符串

时间:2017-07-06 10:08:42

标签: ruby regex

我尝试了其他一些链接,例如Regex Match all characters between two stringsRegex get all content between two characters 但他们似乎不适合这个用例。

我想得到所有的名字,土豆和西红柿。例如,从Jul 13, 2017 6:56:42 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init> INFO: executable: C:\Utility\phantomjs-2.1.1-windows\bin\phantomjs.exe Jul 13, 2017 6:56:42 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init> INFO: port: 13867 Jul 13, 2017 6:56:42 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init> INFO: arguments: [--webdriver=13867, --webdriver-logfile=C:\Users\AtechM_03\LearnAutmation\LearnAutomationTestNG\phantomjsdriver.log] Jul 13, 2017 6:56:42 PM org.openqa.selenium.phantomjs.PhantomJSDriverService <init> INFO: environment: {} [INFO - 2017-07-13T13:26:45.068Z] GhostDriver - Main - running on port 13867 [INFO - 2017-07-13T13:26:46.224Z] Session [eb077d70-67ce-11e7-9bc6-6935b23fd504] - page.settings - {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1","webSecurityEnabled":true} [INFO - 2017-07-13T13:26:46.224Z] Session [eb077d70-67ce-11e7-9bc6-6935b23fd504] - page.customHeaders: - {} [INFO - 2017-07-13T13:26:46.224Z] Session [eb077d70-67ce-11e7-9bc6-6935b23fd504] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.1.1","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"windows-8-32bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"databaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"}} [INFO - 2017-07-13T13:26:46.225Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: eb077d70-67ce-11e7-9bc6-6935b23fd504 Jul 13, 2017 6:56:46 PM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Detected dialect: OSS =====PhantomJS Driver Initiated===== =====URL Accessed===== =====EINLOGGEN button Clicked===== =====Username Sent===== =====Password Sent===== =====Login button Clicked===== [INFO - 2017-07-13T13:27:05.036Z] ShutdownReqHand - _handle - About to shutdown PASSED: testGoogleSearch =============================================== Default test Tests run: 1, Failures: 0, Skips: 0 =============================================== =============================================== Default suite Total tests run: 1, Failures: 0, Skips: 0 =============================================== [TestNG] Time taken by org.testng.reporters.EmailableReporter2@47caedad: 9 ms [TestNG] Time taken by org.testng.reporters.XMLReporter@126253fd: 16 ms [TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@1807f5a7: 246 ms [TestNG] Time taken by org.testng.reporters.jq.Main@415b0b49: 151 ms [TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 0 ms [TestNG] Time taken by org.testng.reporters.JUnitReportReporter@642a7222: 65 ms public class CustomPickerRenderer : PickerRenderer { protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Picker> e) { base.OnElementChanged(e); if (this.Control != null) { var downarrow = UIImage.FromBundle("your image"); var textField = this.Control; textField.RightViewMode = UITextFieldViewMode.Always; textField.RightView = new UIImageView(downarrow); } } }

|

>似乎也不起作用..

请指导我的正则之神。

3 个答案:

答案 0 :(得分:1)

逃避|(?<=\|).*?(?=>)。没有它,积极的lookbehind意味着匹配任何东西

答案 1 :(得分:1)

你忘了逃避管道(|),这现在被解释为交替的指标

使用转义管道的正则表达式:

(?<=\|).*?(?=>)

Here you can see the result

答案 2 :(得分:0)

试试这个:

text.scan(/\|(\w*)\>/).flatten
# Returns => ["potato", "tomato"]

不完全确定为什么会这样。与贪婪和非贪婪的匹配有关。见this