Regex Help: Printable character excluding white space

4 views
Skip to first unread message

Edward Beach

unread,
Aug 15, 2009, 7:03:53 PM8/15/09
to vim_use
Hi All,

I'm trying to get a matchstr function to return me the string of
printable character, excluding the white space. So for example,
:echo matchstr(":foo^[bar", ':\p*')
return "foo" since ^[ is the esc character.

And
:echo matchstr(":foo bar", ':\S*')
returns "foo" as well.

I'm using the colon in this example for the first part in matching the
string, but how do I combine the two printable character and exclude
white space regexes into the same expression so that it can handle
both strings ":foo bar^[bar" and ":foo^]bar bar" and extract "foo"?

Thanks!




Tim Chase

unread,
Aug 15, 2009, 10:22:51 PM8/15/09
to vim...@googlegroups.com

I'm not sure what you want...you say you want the printables,
without spaces, but then you say you only want "foo" which
excludes bar (printable chars) and the colon. You might try one of

echo substitute(':foo^[bar', '[^[:graph:]]\+', '', 'g')
echo substitute(':foo^[bar', '[^[:print:]]\+', '', 'g')
echo matchstr(':foo^[bar', '[[:graph:]]\+')

or some permutation thereof. You may want to read up at

:help substitute()
:h [:graph:]
:h [:print:]

If you give a clearer list of inputs and desired outputs, it
might be possible to give a more precise answer.

-tim

Reply all
Reply to author
Forward
0 new messages