How to use RegExpr in scripts

If you need help on how to use the program
Post Reply
fulvio53s03
Posts: 765
Joined: 2007-04-28 05:46:43
Location: Italy

How to use RegExpr in scripts

Post by fulvio53s03 »

I need a Regular Expression to change strings like these:
'<li class="h6 anno"><strong>DURATA</strong>: 45 Min</li>
'<li class="h6 anno"><strong>DURATA</strong>: 63 Min</li>

into:
'<li class="h6 anno"><strong>DURATA</strong>: variabile</li>
:??:
Do you think it could be possible?
Would you give me an example?
Thanks!

:)
antp
Site Admin
Posts: 9665
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

What do you need to do exactly? Extract the number of minutes and put it in a variable?
The syntax here is quite annoying to write due to all the special characters, it is easier to use the "TextBetween" function from StringUtils1 to get what's between these two fixed texts...
fulvio53s03
Posts: 765
Joined: 2007-04-28 05:46:43
Location: Italy

Post by fulvio53s03 »

antp wrote:What do you need to do exactly? Extract the number of minutes and put it in a variable?
The syntax here is quite annoying to write due to all the special characters, it is easier to use the "TextBetween" function from StringUtils1 to get what's between these two fixed texts...
You are almost right and, indeed, this what I did in my last update script, comingsoon.it.
I was looking for such an answer as I don't well understand regexpr's sintax and use..... and I cannot find examples in AMC scripts.
Would you give us some examples?
e.g.:
how to delete all strings between two delimiters (such as 'xxxx' or 'yyyy')?how to delete all numbers between two delimiters (such as 'xxxx' or 'yyyy')?
thanks.
antp
Site Admin
Posts: 9665
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

regex are more useful to handle strings where the content is not known at all, but just the content "type".
For example you know that somewhere in a string there is the time as one or two numbers followed by ":" followed by two numbers.
The expression to find that would be:

Code: Select all

(\d{1,2}):(\d{2})
giving you the two numbers in $1 and $2 (or \1 and \2 depending on the syntax used by the engine) available for generating a new string, do a string replacement, or provided values in an array of results.
- parenthesis ( ) indicate groups that you want to catch for extract/re-use
- the \ followed by something is either special character meaning (here \d for decimal number) or escaping a special character for regular use (\. for a dot, as the dot alone means "any character")
- braces { } are for number of occurrences of the type of character defined just before.
I do not know how it is handled in AMC exactly since it was added by soulsnake and I haven't use these there yet (you'll have to check Help and/or other scripts for samples), but I use these a little everywhere.
For more info on the syntax try to find samples on internet, as it is impossible to describe quickly everything.
Post Reply