Home > other >  Match a string between hash symbols
Match a string between hash symbols

Time:09-29

I have a string in this shape

State#Received#ID#e23d8926-1327-4fde-9ea7-d364af3325e0

I want to extract the State value via RegEx. So in this above example I only want to extract Received

I have tried the following ([^State#])([A-Za-z]) which matches Received but I am stuck at excluding the rest of the string #ID#e23d8926-1327-4fde-9ea7-d364af3325e0

CodePudding user response:

You should not use a parenthesis for the group you don't want to capture. My solution is that:

State#(?'state'[^#] )#

Sample: https://regex101.com/r/vAr65j/1

  • Related