regex - Match a string with regexp -
i having string like
-------- agg x y port-16385-info ----------------------------+
i want extract "agg x y port-16385-info ". pattern in not same. can have number of spaces inbetween .
help me regexp string.
i using regexp
regexp {\s+(.*)\-\-*} $a -
ouput
agg port-16385-info ---------------------------
this not want. me regexp.
well, i'll assume delimiter @ least 2 -
long , seperated via space contents. trivial regex like
--\s+(.*?)\s+--
would work. *?
quantifier non-greedy matching, terminate possible.
if regex works depends on allowed values , exact format of input, have not sufficiently explained.
i suprised tagged perl — quite sure code isn't valid perl code.
if not want use .
character class, can rewrite match non-hyphen characters or single hyphen followed non-hyphen:
--\s+((?:[^-]+|-[^-])*)\s+--
you might want disallows newlines along hyphens well.
Comments
Post a Comment