Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

tcl how to split a string by using regexp

I have some string with format

class(amber#good)
class(Back1#notgood)
class(back#good)

and I want to use regexp to get value of these string

Expected answer:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

amber
Back1
back

And here’s my cmd:

set string "class(amber#good)"
regexp -all {^\\([a-zA-z_0-9].\#$} $string $match
puts $match

But the answer is not what I expected

>Solution :

You can use

regexp {\(([^()#]+)} $string - match

See the Tcl demo online.

The \(([^()#]+) regex matches

  • \( – a ( char
  • ([^()#]+) – Capturing group 1 (match): any one or more chars other than parentheses and #.

The hyphen is used since the match value is not necessary, we are only interested to get Group 1 value.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading