How to create a regex in ruby to (1)filter out everything after a string and to (2) filter something in the middle of a line? -
case 1: consider line:
[2014-03-05 17:21:39 -0800] this.computer.name - select file: f7de1.png
i need filter out after "select file: ". in need filename sentence above.
case 2: consider line:
[2014-03-05 17:21:39 -0800] this.computer.name - cycle: 12345 file: f7de1.png
i need filter cycle number here, 12345
for both these cases here, filename can different lengths different cycles.
first case:
str = "[2014-03-05 17:21:39 -0800] info this.computer.name - select file: f7de1.png" str[/file: (.+)/, 1] => "f7de1.png"
second case:
str = "[2014-03-05 17:21:39 -0800] info this.computer.name - cycle: 12345 file: f7de1.png" str[/cycle: (\d+)/, 1] => "12345"
Comments
Post a Comment