简体   繁体   中英

RegEx multiple steps in ruby

Given the string below:

"oxcCFC/video.mp4 "GET /accounts/6/videos/xboxcCFC/video.mp4 HTTP/1.1" 206 - 2 697898511 56 56 "-""

How would I create a regular expression that first finds "HTTP, then finds "-", and then captures the next indiviual number or consecutive numbers that occurs in the sequence?

I'm trying to use rubular but struggling big time.

Not a lot to go on, but I think it should be something like this:

/^.*\s+HTTP.*\s+-\s+(\d+)\s+/

A backreference will then hold the value you're after.

我想看看你是否可以使用 apachelogregex gem ... http://rubydoc.info/gems/apachelogregex/0.1.0/frames

Short answer: /HTTP[^-]*-([\\d\\s]+)/ then, call split on the result.

This regexp translates to:

"HTTP", followed by any number of non-hyphen characters, followed by a hyphen, followed by the largest string consisting only of digits and spaces.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM