Hello
Can anyone figure this one out? Here is my string:
Esko ArtiosCAD - [TEST - 0 mfg]
This text is always the same
This text is always different
This is the text i need to get
I have never used regex before, so i'm very lost here.
Help with Regex
Moderators: JRL, Dorian (MJT support)
- Dorian (MJT support)
- Automation Wizard
- Posts: 1417
- Joined: Sun Nov 03, 2002 3:19 am
Re: Help with Regex
This regex returns "everything between"
Code: Select all
//To help you understand
let>mystring=Esko ArtiosCAD - [TEST - 0 mfg]
let>BEGINNING=0
let>END=]
RegEx>(?<=%BEGINNING%).*?(?=%END%),mystring,0,matches,nm,0
MessageModal>%nm% matches %CRLF%The item number is %matches_1%
//All condensed into one line
RegEx>(?<=0 ).*?(?=]),Esko ArtiosCAD - [TEST - 0 mfg],0,matches,nm,0
MessageModal>%nm% matches %CRLF%The item number is %matches_1%
- Grovkillen
- Automation Wizard
- Posts: 1132
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: Help with Regex
A piece of advice, pay for regexBuddy
- Dorian (MJT support)
- Automation Wizard
- Posts: 1417
- Joined: Sun Nov 03, 2002 3:19 am
Re: Help with Regex
Also, here's a free Regex course. It helped me grasp a basic understanding.
https://www.udemy.com/course/regex-acad ... g-sorcery/
Re: Help with Regex
Thank you Dorian. Very helpful.Dorian (MJT support) wrote: ↑Thu Nov 07, 2019 1:06 pmThis regex returns "everything between"
Code: Select all
//To help you understand let>mystring=Esko ArtiosCAD - [TEST - 0 mfg] let>BEGINNING=0 let>END=] RegEx>(?<=%BEGINNING%).*?(?=%END%),mystring,0,matches,nm,0 MessageModal>%nm% matches %CRLF%The item number is %matches_1% //All condensed into one line RegEx>(?<=0 ).*?(?=]),Esko ArtiosCAD - [TEST - 0 mfg],0,matches,nm,0 MessageModal>%nm% matches %CRLF%The item number is %matches_1%
One more question: How would you write it, if you wanted to define "End" like you did, but instead of defining the Beginning, you just want to start from the beginning of the string?
This question is unrelated to my first question. I don't need to do that in that code .
Thanks guys. I will try the course and will consider buying regexbuddy.
- Dorian (MJT support)
- Automation Wizard
- Posts: 1417
- Joined: Sun Nov 03, 2002 3:19 am
Re: Help with Regex
So "everything in front of" instead of "everything between"?. Maybe one of the Regex gurus in here can show you that in Regex, but you don't need regex for that. Macro Scheduler can do that with Position, Length, and Midstr.
Get everything before G :
Get everything before G :
Code: Select all
Let>MyString=ABCDEFGHIJKLMNOPQRSTVUWXYZ
Len>MyString,MyStringLen
Pos>G,MyString,1,PosChar,
Midstr>MyString,1,{(%Poschar%-1)},MyNewString
MessageModal>MyNewString
Re: Help with Regex
@Scones,
Here is a RegEx that will grab what you need.
^ = start of string
.* = every character 0 or more times (up to the next specified character) Which is [.
\[ = Because RegEx uses [ in arguements, we use \ to let regex know it's part of what we are looking for.
.* = every character 0 or more times (up to the next specified character)
- 0 = text we are expecting. Literal.(There is a space before the hyphen(-). A space is a character.)
() = tells regex to remember what is between these parentheses. It's called a group.
(.*) = remember everything in this group (up to the next specified character) Which is ].
\] = same as [
Hope this helps,
PepsiHog
Here is a RegEx that will grab what you need.
Code: Select all
let>mystring=Esko ArtiosCAD - [TEST - 0 mfg]
RegEx>^.* \[.* - 0 (.*)\],mystring,0,match,nom,1,$1,TextYouNeed
mdl>%TextYouNeed%
.* = every character 0 or more times (up to the next specified character) Which is [.
\[ = Because RegEx uses [ in arguements, we use \ to let regex know it's part of what we are looking for.
.* = every character 0 or more times (up to the next specified character)
- 0 = text we are expecting. Literal.(There is a space before the hyphen(-). A space is a character.)
() = tells regex to remember what is between these parentheses. It's called a group.
(.*) = remember everything in this group (up to the next specified character) Which is ].
\] = same as [
Hope this helps,
PepsiHog
Windows 7
PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)
The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!
PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)
The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!