Pattern Matching with special characters

I am new to Intersystems Cache, so please bear with me. We are using HealthShare 2013.1. 

I have a routine to compare databases from separate instances where I want to ignore values that begin with %sqlcq. I thought this would be easy with pattern matching operator '?' but it is proving difficult and it seems to be because of the percent character. 

For example:

set x = "%sqlcq.something.value.foo"

#;does not evaluate as true. 
if x?1P1"sqlcq" {write "valid"}

set y="sqlcq.something.value.bar"

if y?1"sqlcq".E {write "valid"}
valid
if x?1"sqlcq".E {write "valid"}

  

If the variable value does not include the leading percent character, then I can successfully match. If it does include the percent character then it fails. 

I did try the following pattern, x?1P.1"sqlcq".E and I thought this was successful, but it ended up ignoring %SYS.FOO

What am I missing with pattern matching here? 

Thank you.

Dan Lee
Amazing Charts | Harris Computer

  • 0
  • 0
  • 91
  • 2
  • 2

Answers

Maybe you want something like this:

set data1 = "%sqlcq.something.value.foo"
set data2 = "sqlcq.something.value.bar"

for x=data1, data2 { if x ? .1"%"1"sqlcq".e { write "OK" } else { write "NOT" } w ! }

Your output should be:
OK
OK

Regards

This seems to work for me:

set x = "%sqlcq.something.value.foo"

write x?1"%sqlcq".E

That said, I assume you're iterating over some list of classes. If so, it may be better to add this or equivalent condition to the builder of the class list. If you do it via SQL and %Dictionary package, then excluding System classes, or generated classes or even classes that %STARTSWITH '%sqlcq' may be a better solution.

Comments

I just found the $MATCH method which works. 

if $MATCH(p, "^%sqlcq.*"){
                    write "Skipping "_p,!
                    continue
                }

I find it simpler to use $Extract,
e.g. $E(x,1,7)="%sqlcq."