RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Extracting bible verses with Vim
Expression
/(\d?\s?\w+),(\d+),(\d+),(/d*),/\1 \2:\3-\4/g
Description
I had a CSV file with following format: book,chapter,verse_start,verse_end,notes I wanted to transform the rows to traditional english verse representations (i.e. "1 Timothy 2:2-4") Unfortunately, this regex always puts a '-' after the verse_start, so if verse_end is empty, the translated version will have a trailing '-'. Vim needs everything escaped, so here is the actual vim command for the substitution: :%s/\(\d\?\s\?\w\+\),\(\d\+\),\(\d\+\),\(\d*\),/\1 \2:\3-\4/g
Matches
1 Timothy,2,2,4,|John,6,3,,|A,123,4,4,
Non-Matches
12 Timothy,2,2,4,|2 Timothy 2,2,4|A Corinthians 3,3,,|John,3,,,|John,3,,3,
Author Rating: Not yet rated. Tyler Durkota
Source Lots of experimentation
Your Rating
Bad Good

Enter New Comment

Title
 
Name
 
Comment
 
Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials