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+-- 

regular expression visualization

you might want disallows newlines along hyphens well.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -