Home > Blockchain >  Regex to get substring repeat in a string
Regex to get substring repeat in a string

Time:07-25

I have strings like this "$a477tr.: $bBìa mềm ; $c13x18.8cm" and I wanna get the all substrings after $a, $b, $c, ... . The expected results (included space):

$a "477tr.: "
$b "Bìa mềm ; "
$c "13x18.8cm"

I've used regex101 and tried the pattern but the result I got is

$a "477tr.: $bBìa mềm ; $c13x18.8cm". 

I've tried some other patterns but I couldn't get the right results.

Please help.

CodePudding user response:

(?<=\$[a-z0-9])(?<content>[^\$]*) should do the job.

: "${content}"\n - the substitution pattern if needed.

CodePudding user response:

I'm not familiar with regex101, but in regexr.com this pattern works:

(\$[a-z])([^$] )

At this site, you have to choose List in Tools and write this:

$1 "$2"\n

After that, you will have this output:

$a "477tr.: "
$b "Bìa mềm ; "
$c "13x18.8cm"
  • Related