Note that there are some explanatory texts on larger screens.

plurals
  1. POVIM: Delete pattern IF submatch(1) is empty
    text
    copied!<p>This command line parses a contact list document that may or may not have either a phone, email or web listed. If it has all three then everything works great - appending the return from the FormatContact() at the end of the line for data uploading:</p> <pre><code>silent!/^\d/+1|ki|/\n^\d\|\%$/-1|kj|'i,'jd|let @a = substitute(@",'\s*Phone: \([^,]*\)\_.*','\1',"")|let @b = substitute(@",'^\_.*E-mail:\s\[\d*\]\([-_@.0-9a-zA-Z]*\)\_.*','\1',"")|let @c = substitute(@",'^\_.*Web site:\s*\[\d*\]\([-_.:/0-9a-zA-Z]*\)\_.*','\1',"")|?^\d\+?s/$/\=','.FormatContact(@a,@b,@c) </code></pre> <p>or, broken down:</p> <pre><code>silent!/^\d/+1|ki|/\n^\d\|\%$/-1|kj|'i,'jd let @a = substitute(@",'\s*Phone: \([^,]*\)\_.*','\1',"") let @b = substitute(@",'^\_.*E-mail:\s\[\d*\]\([-_@.0-9a-zA-Z]*\)\_.*','\1',"") let @c = substitute(@",'^\_.*Web site:\s*\[\d*\]\([-_.:/0-9a-zA-Z]*\)\_.*','\1',"") ?^\d\+?s/$/\=','.FormatContact(@a,@b,@c) </code></pre> <p>I created three separate searches so as not to make any ONE search fail if one atom failed to match because - again - the contact info may or may not exist per contact.</p> <p><strong>The Problem</strong> that solution created was that when the pattern does not match I get the whole @" into @a. Instead, I need it to be empty when the match does not occur. I need each variable represented (phone,email,web) whether it be empty or not.</p> <ol> <li>I see no flags that can be set in the substitution function that will do this.</li> <li>Is there a way to return "" if \1 is empty?</li> <li>Is there a way to create an optional atom so the search query(ies) could still account for an empty match so as to properly record it as empty? </li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload