* Robin Anson writes:
> On Tue 30 March 2004, 2:54:02 +1000, Marck D Pearlstone wrote:

> MDP>>> %IF:"%ABtoGender"="0":"Spett.le":"Egr." %-
> MDP>>> %SETPATTREGEXP="(.*)( - .*)?"%-
> MDP>>> %REGEXPBLINDMATCH="%ABTOLASTNAME='%TOLNAME'"%-
> MDP>>> %SUBPATT(1)

> JO>> Don't Know why the brackets in ( - .*)? are useless, but it's running
> JO>> well.

>> They are important if you have any records without either "- work"
>> or "- home" at the end. Then the expression will fail to match
>> completely and result in a blank name. My version is the one to use.

> When I tried this on an entry with "smith - home" as the last name, the
> first expression matched the entire last name and left a zero occurrence
> of the second expression. I thought the way around this was to set the
> first expression in the regex to be "(.*?)" (I think the term is
> non-greedy), but that simply failed to match anything then.

> Can anyone explain why that might be the case?

It's because the pattern doesn't need to match the whole subject.

This regexp should work: "^(.*?)(?: - .*)?$"

--8<---------------cut here---------------start------------->8---
%_testa="smith - work"
%_testb="smith"
%_testa
%_testb
----
%setpattregexp="^(.*?)(?: - .*)?$"%-
1. a) %regexpmatch="%_testa"
   b) %regexpmatch="%_testb"
---
%setpattregexp="(.*?)(?: - .*)?"%-
2. a) %regexpmatch="%_testa"
   b) %regexpmatch="%_testb"
--8<---------------cut here---------------end--------------->8---

Carsten
-- 


________________________________________________
Current version is 2.04.7 | 'Using TBUDL' information:
http://www.silverstones.com/thebat/TBUDLInfo.html

Reply via email to