Network Automation Software We are currently migrating this forum
over to our HelpSystems domain. Please
post all new threads in our new
HelpSystems Community Portal.
Post to the HelpSystems Forum
You are not currently logged on. You must be logged on in order to post. Log on
Or Create a new account
AutoMate Discussion
Decrease font size
Increase font size
Topic Title: Careful Using Variables Inside Regular Expressions
Topic Summary: If X="A+B=C", the "+" needs to be Replaced as "\+"
Created On: 09/21/2009 09:03 AM
Status: Read Only
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
View similar topics View similar topics
View topic in raw text format. Print this topic.
 09/21/2009 09:03 AM
User is offline View Users Profile Print this message

Author Icon
EvanEvans
Journeyman (50-99)

Posts: 86
Joined: 09/02/2009

It took me a few hours to figure this one out. Why was a step which was finding text, was ending my task on error, every time it parsed some HTML, but in 100s of other cases it never occured.

It turned out that on occassion, the contents of a variable I was using as a search stop {ie: (?<=Variable).*?(?=end search)}, contained illegal regular expression characters that needed to be escaped.

I'm sure this is basic knowledge to most professional programmers, but as a very experienced programmer, albeit an amateur, it took me longer to figure out.

I hope this helps anyone in the future!

 Category Survey
 09/22/2009 08:43 AM
User is offline View Users Profile Print this message

Author Icon
EvanEvans
Journeyman (50-99)

Posts: 86
Joined: 09/02/2009

Here's a cleaner Expression I put together:

Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(IMDbContact,"\","\\"),"(","\("),")","\)"),"+","\+"),"*","\*"),"$","\$"),".","\."),"?","\?"),"|","\|")

It traps for the escape character \ and then escapes it by replacing it with \\, it then proceeds to add the escape character \ before any of the following:

|?+.*()$

I got lazy and left out:

{}[]

So be sure to add those in if in your case your strings might contain them.

 Category Survey
 09/22/2009 11:43 AM
User is offline View Users Profile Print this message

Author Icon
Dustin Snell
AUTOMATE EMPLOYEE

Posts: 1656
Joined: 03/30/2005

lol - that is some expression you have there!

 Category Survey


-------------------------
Dustin Snell
 10/05/2009 10:15 AM
User is offline View Users Profile Print this message

Author Icon
EvanEvans
Journeyman (50-99)

Posts: 86
Joined: 09/02/2009

Ha. I know isn't it?

All it is, is, put a \ before the following characters: \()+*$.?|

If there is a simpler function for that, I am all ears!



 Category Survey
 10/05/2009 11:42 AM
User is offline View Users Profile Print this message

Author Icon
JeanDelfosse
Supreme Guru (1000+)

Posts: 8883
Joined: 03/30/2005

Regex with back reference would do it, but the AM implementation does not.

 Category Survey
AutoMate 7 version:
Windows version:


-------------------------
Jean Delfosse - Automate Beta Tester
Win7 Pro 64 bits -Win XP Pro SP3 32 bits - AM8, AM7, BPA10, BPA9, BPA8, BPA7, AM6 Enterprise, AM4
 10/05/2009 01:50 PM
User is offline View Users Profile Print this message

Author Icon
EvanEvans
Journeyman (50-99)

Posts: 86
Joined: 09/02/2009

Do you mean to say AM doesn't allow for backreferencing RegEx, or you are just saying that AM doesn't have a builtin action to do something similar? Because I would be interested in seeing the code for this in backreferenced RegEx style since I am somewhat new to backreferences. I want to learn more about them, but the examples on the net are hard to understand, often with cryptic examples. This is a practical application I can understand, so if you are a RegEx wiz, please show me, I promise to learn, and teach it to others.

 Category Survey
 10/05/2009 11:40 PM
User is offline View Users Profile Print this message

Author Icon
JeanDelfosse
Supreme Guru (1000+)

Posts: 8883
Joined: 03/30/2005

Evan,
I'm not a regex wiz. Just a student.
But I could never get regex backreferences to work in AM7,
while it did in AM6 (old regex engine only, but failed with the .net engine)

I would appreciate N/A to give an answer, and also a working sample.

Instead it works nicely in basic scripts as below
You could use the funtion I made, and invoke it inside expressions in AM

 Category Survey
AutoMate 7 version:
Windows version:



Task Steps: (Right click, Select All, Copy to copy to the clipboard. Steps can then be pasted into the AutoMate Task Builder)


-------------------------
Jean Delfosse - Automate Beta Tester
Win7 Pro 64 bits -Win XP Pro SP3 32 bits - AM8, AM7, BPA10, BPA9, BPA8, BPA7, AM6 Enterprise, AM4


Edited: 10/06/2009 at 12:05 AM by JeanDelfosse
 10/06/2009 12:00 AM
User is offline View Users Profile Print this message

Author Icon
EvanEvans
Journeyman (50-99)

Posts: 86
Joined: 09/02/2009

So kind. Thank you. I'll analyze this and let you know if I have any questions. Thanks again.

 Category Survey
 10/06/2009 12:07 AM
User is offline View Users Profile Print this message

Author Icon
JeanDelfosse
Supreme Guru (1000+)

Posts: 8883
Joined: 03/30/2005

I transformed the basic sample into a function. so that you can use it whereever you need

 Category Survey
AutoMate 7 version:
Windows version:


-------------------------
Jean Delfosse - Automate Beta Tester
Win7 Pro 64 bits -Win XP Pro SP3 32 bits - AM8, AM7, BPA10, BPA9, BPA8, BPA7, AM6 Enterprise, AM4
 10/16/2015 09:53 PM
User is offline View Users Profile Print this message

Author Icon
AnthonyHogan
Journeyman (50-99)

Posts: 79
Joined: 07/12/2015

Did you ever hear back from N/A about the correct syntax? I'm having issues in Automate 10 trying to use \1 or $1 in regexps.

http://forums.networkautomation.com/forum/messageview.cfm?catid=72&threadid=13609



 Category Survey
AutoMate 7 version:
Windows version:
 10/23/2015 02:18 PM
User is offline View Users Profile Print this message

Author Icon
Ricardo Castaneda
HelpSystems

Posts: 3424
Joined: 01/11/2008

Hi Anthony,

Are you running into a specific error?

Can you post a reproducible case?

 Category Survey


-------------------------

Ricardo Castaneda | Principal Support Analyst
AutoMate | Division of HelpSystems
HelpSystems, LLC | T: +1.213.738.1700
Statistics
18258 users are registered to the AutoMate Discussion forum.
There are currently 0 users logged in.
The most users ever online was 5551 on 01/08/2018 at 11:11 AM.
There are currently 1356 guests browsing this forum, which makes a total of 1356 users using this forum.

FuseTalk Enterprise Edition v4.0 - © 1999-2020 FuseTalk Inc. All rights reserved.

Sitemap Network Automation Software Blog