Regex expression to match command output -
filename eof xxxxxxx 101 241434 12dec2011 9:33 255,255 uuuu 14 42 xxxxxxx 101 114682 12dec2013 11:49 220,0 uuuu 14 42 xxxxxxxx 101 200542 14dec2011 14:43 255,255 uuuu 14 42 xxxxxxxx 101 200458 25jan2012 15:28 220,0 nuuu 14 42 xxxxxxxx 101 8102 28jan2015 15:17 227,12 nccc 14 14 xxxxxx 101 114502 12dec2013 11:49 220,0 uuuu 14 42 xxxxxxx 101 4622 23jan2012 14:46 255,255 uuuu 14 42 xxxxxxxx 101 120 18apr2013 16:20 201,130 oooo 14 28 xxxxxx 101 48298 03jan2013 8:47 90,2 oooo 14 14 xxxxx 101 200686 07dec2011 15:59 255,255 uuuu 14 42 xxxxxxxx 101 3578 30jan2014 18:14 255,255 uuuu 14 42
from output want match filename , eof filename only. tired \s\d+\s\d
, able match eof find little challeage match filename eof
you can use :
^([\w\.]+)\s+\d+\s+(\d+)
group 1 contain filename , group 2 contain eof
explanation:
^
anchor tells engine start of line.
\w
matches word characters (alphanumeric , underscore)
\s
matches whitespace character (spaces, tabs, line breaks)
\d
matches digit character [0-9]
+
matches 1 or more of preceding token
\.
matches dot . character
[...]
character set, matches character inside set
(...)
capturing group, groups inside extracting substring
so in mind can see pattern doing:
you should tell engine start of line ^
want capture first group of alphanumeric chars ([\w\.]+)
here i'm assuming name of file may contain dot. if may have other characters -, should change part ([\w\.-]+)
or whatever may need match.
then tell string have @ least 1 whitespace, may have more \s+
. tell have @ least 1 digit, might have more \d+
(since not interested in don't put in capture group) more whitespacing \s+
more digits, these interested in capturing, put in parenthesis (\d+)
.
hope helps understand little more regex, cheers!
Comments
Post a Comment