Hi.
Given the string: X1aaX1bbX1ccY
I need to pull out anything between the last X1 and Y. Anything, of any length, is allowed in the aa, bb, or cc positions. I believe it will require a look-ahead or a look-behind, but I can't solve it. I have been pondering for hours. sigh.
e.g.
X1aaX1bbX1ccY should return "cc"
X1aaX1bbX1ccabcY should return "ccabc"
X1aaX1bbX1cc1Y should return "cc1"
etc...
Thanks in advance.
Regex help please
Moderator: General Moderators
Re: Regex help please
This worked for me:
Results from your 3 examples
[text] Start Length
Match 1: X1aaX1bbX1ccY 0 13
Group 1: cc 10 2
Match 2: X1aaX1bbX1ccabcY 15 16
Group 1: ccabc 25 5
Match 3: X1aaX1bbX1cc1Y 33 14
Group 1: cc1 43 3[/text]
Code: Select all
^.*X1(.*)Y$[text] Start Length
Match 1: X1aaX1bbX1ccY 0 13
Group 1: cc 10 2
Match 2: X1aaX1bbX1ccabcY 15 16
Group 1: ccabc 25 5
Match 3: X1aaX1bbX1cc1Y 33 14
Group 1: cc1 43 3[/text]
Re: Regex help please
Thank you, thank you TwinDev! I'm going to study that and try to understand it. Not sure how it works...? Are the ^ and the $ necessary?