LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-14-2012, 09:32 AM   #1
porphyry5
Member
 
Registered: Jul 2010
Location: oregon usa
Distribution: Slackware 14.1, Arch, Lubuntu 18.04 OpenSUSE Leap 15.x
Posts: 518

Rep: Reputation: 24
vimscript; remove file suffix with substitute()


On a line containing
Code:
Parameters2.html
:s/\..*//
produces
Parameters2
But using substitute()
Code:
:echo substitute("Parameters2.html", "\..*", "", "")

:echo substitute("Parameters2.html", "\..*$", "", "")

:echo substitute("Parameters2.html", "\([^.]\)*\..*$", "\1", "")
Parameters2.html
:echo substitute("Parameters2.html", "\([^\.]\)*\..*$", "\1", "")
Parameters2.html
How should I be writing this?
 
Old 10-14-2012, 05:04 PM   #2
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
Hi,
Code:
:echo substitute("Parameters2.html", "[.].*", "", "")
this will work.

Markus
 
1 members found this post helpful.
Old 10-15-2012, 09:38 AM   #3
porphyry5
Member
 
Registered: Jul 2010
Location: oregon usa
Distribution: Slackware 14.1, Arch, Lubuntu 18.04 OpenSUSE Leap 15.x
Posts: 518

Original Poster
Rep: Reputation: 24
Quote:
Originally Posted by markush View Post
Hi,
Code:
:echo substitute("Parameters2.html", "[.].*", "", "")
this will work.

Markus
Many thanks. I also found
Code:
:echo expand("%:r")
to solve my immediate problem, but its very useful to know this method to get substitute() to live up to the promise of its :help description.

But for general application. I found the problem concerns the type of quoting used on the regex
Code:
:echo substitute("Parameters2.html", '\..*', "", "")
Parameters2
or
:echo substitute("Parameters2.html", "\\..*", "", "")
Parameters2
i.e. for double quoted strings, double the backslashes; or use single quoted strings.
:h expr-string
:h literal-string

Last edited by porphyry5; 10-16-2012 at 09:51 AM. Reason: Found general solution
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
checking for suffix of object files... configure: error: cannot compute suffix of obj megras Linux - Kernel 1 10-15-2012 07:21 AM
[SOLVED] Vimscript: using substitute() on a variable porphyry5 Programming 2 10-09-2011 04:54 AM
Default word processor (association with file suffix?) linuxbird Linux - Newbie 4 01-23-2011 11:34 AM
[SOLVED] Substitute Text from Master File dougp23 Programming 11 05-16-2010 12:20 AM
Substitute String or line in a file dimsh Linux - Newbie 4 09-21-2005 03:26 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration