RegEx-got it to work but don't understand a few things

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
BlackCat
Newbie
Posts: 13
Joined: Mon Dec 20, 2010 12:32 am

RegEx-got it to work but don't understand a few things

Post by BlackCat » Thu Jan 20, 2011 3:56 am

I figured out the code I needed, but I don't understand part of the RegEx line. I found this blog post http://www.mjtnet.com/blog/2009/04/30/r ... r-dummies/ that pointed to RegExr which I used to figure out my pattern. This was much easier for me to understand than the reference posted in the help.

I am having trouble understanding the following portion of the RegEx command (,0,matches,num). What does the first 0 or 1 stand for? It wasn't clear to me from reading the help. I used the examples in the help and changed the first number until I achieved my desired result. Is "matches" the variable used to store the pattern matched? And "num" stores the number of matches? So, when using the command "MessageModal>matches_1" it is saying display the first match found by the command? And if I wrote "MessageModal>matches_2" and there where two matches I would be shown the 2nd match?

Thanks for the help.

My code below:

Code: Select all

//Long Version
Let>text=D:\BlackCats_Documents\My_Videos\DVD\Action\MovieNameHere
Let>pattern=(\w\D\S+\\)
RegEx>pattern,text,0,matches,num,0
MessageModal>matches_1
StringReplace>text,matches_1,,strNewString
MessageModal>strNewString




//Best Version
Let>text=D:\BlackCats_Documents\My_Videos\DVD\Action\MovieHere
Let>pattern=(\w\D\S+\\)
RegEx>pattern,text,0,Matches,NumMatches,1,,MovieName
MessageModal>MovieName

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Jan 20, 2011 6:34 am

You are correct. Matches is an array variable which stores each match, and num is the number of matces.

The first zero tells the command to use RegEx. If you set it to 1 it would use the EasyPatterns format instead.

The help file explains all:
RegEx>pattern,text,easypatterns,matches_array,num_matches,replace_flag[,replace_string,replace_result]

Performs the regular expression in pattern on text, returning the number of sub matches in num_matches and the text found in matches_array. RegEx is compatible with the Perl 5.10 regular expression syntax using the PCRE library.

matches_array is the name of a variable to store the results. The first match is stored in matches_array_1, the second in matches_array_2, etc.


To perform a replacement set replace_flag to 1 and specify the replacement string in replace_string and the return variable in replace_result. Otherwise set replace_flag to 0.

By setting easypatterns to 1 pattern can use EasyPatterns syntax. EasyPatterns uses an english-like structure to simplify the use of regular expressions. See the EasyPatterns Reference.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

BlackCat
Newbie
Posts: 13
Joined: Mon Dec 20, 2010 12:32 am

Post by BlackCat » Fri Jan 21, 2011 6:16 am

Thanks for pointing that out. It makes sense now.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts