Jump to content
Sign in to follow this  
E1M1

need help with StringRegExp()

Recommended Posts

E1M1

I want to see if file extension is .doc or .xls but for some reason it returns always 1. I have file.dox so it should return 0 but it don't.

MsgBox(0,0,StringRegExp ( "file.dox", "[.doc.xls]" ,0 ))

i also tried

MsgBox(0,0,StringRegExp ( "file.dox", "[*.doc*.xls]" ,0 ))

but it didn't work either

Edited by E1M1

edited

Share this post


Link to post
Share on other sites
dani

$1 = "file.doc"  ; True
$2 = "file.xls"  ; True
$3 = "file.docx" ; False

; (?i) = case insensitive, \z = end of string, (?:doc|xls) = match 'doc' OR 'xls', 
; \. = match '.', \ = escape character to match special characters literally, like ., [, ( etc.

; So what this says is: 'Match anything that ends with either .DOC, .doc, .XLS or .xls'.
$regEx = "(?i)\.(?:doc|xls)\z"

MsgBox(0, "", StringRegExp($1, $regEx))
MsgBox(0, "", StringRegExp($2, $regEx))
MsgBox(0, "", StringRegExp($3, $regEx))

Edited by d4ni

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.