Home > Software engineering >  Marking the last character from the matched string
Marking the last character from the matched string

Time:08-11

I want to mark the last character from the matched string in regex101 or notepad regex. To be marked the last space before the }.

Here’s my example(tried), Regex: https://regex101.com/r/0QNOD1/1

input:

[]*} %>  ~€_€<]%,!!_€~
“ABC/A1/YY-“ abc1 
    }
!£|€_€{^}?![ }|!¥]
“ABC/A2/YY-“ abc2
    }
18,&4&5&4&&1$&((&&1
“ABC/A3/YY-“ abc7
    }

Result After Replacement

[]*} %>  ~€_€<]%,!!_€~
“ABC/A1/YY-“ abc1 
    SEND}
!£|€_€{^}?![ }|!¥]
“ABC/A2/YY-“ abc2
    SEND}
18,&4&5&4&&1$&((&&1
“ABC/A3/YY-“ abc7
    SEND}

CodePudding user response:

You can search using this regex:

ABC/A\d /YY-“\ abc\d \s*[\s\S]? \K(?=})

And replace it with:

SEND

Updated RegEx Demo

RegEx Details:

  • ABC/A: Match ABC/A
  • \d : Match 1 digits
  • /YY-“\ abc:
  • \d : Match 1 digits
  • \s*: Match 0 whitespaces
  • [\s\S]? : Match an optional character including line break. after ? is possessive quantifier.
  • \K: Reset match info
  • (?=}): Lookahead to make sure we have } at next position
  • Related