Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 970127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:45:25+00:00 2026-05-16T02:45:25+00:00

hi everybody i want solution for this regular expression, my problem is Extract all

  • 0

hi everybody i want solution for this regular expression, my problem is Extract all the hex numbers in the form H'xxxx, i used this regexp but i didn’t get all hexvalues only i get one number, how to get whole hex number from this string

set hex "V5CCH,IA=H'22EF&H'2354&H'4BD4&H'4C4B&H'4D52&H'4DC9"
set res [regexp -all {H'([0-9A-Z]+)&} $hex match hexValues]
puts "$res H$hexValues"

i am getting output is 5 H4D52

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T02:45:25+00:00Added an answer on May 16, 2026 at 2:45 am

    On -all -inline

    From the documentation:

    -all : Causes the regular expression to be matched as many times as possible in the string, returning the total number of matches found. If this is specified with match variables, they will contain information for the last match only.

    -inline : Causes the command to return, as a list, the data that would otherwise be placed in match variables. When using -inline, match variables may not be specified. If used with -all, the list will be concatenated at each iteration, such that a flat list is always returned. For each match iteration, the command will append the overall match data, plus one element for each subexpression in the regular expression.

    Thus to return all matches –including captures by groups– as a flat list in Tcl, you can write:

    set matchTuples [regexp -all -inline $pattern $text]
    

    If the pattern has groups 0…N-1, then each match is an N-tuple in the list. Thus the number of actual matches is the length of this list divided by N. You can then use foreach with N variables to iterate over each tuple of the list.

    If N = 2 for example, you have:

    set numMatches [expr {[llength $matchTuples] / 2}]
    
    foreach {group0 group1} $matchTuples {
       ...
    }
    

    References

    • regular-expressions.info/Tcl

    Sample code

    Here’s a solution for this specific problem, annotated with output as comments (see also on ideone.com):

    set text "V5CCH,IA=H'22EF&H'2354&H'4BD4&H'4C4B&H'4D52&H'4DC9"
    set pattern {H'([0-9A-F]{4})}
     
    set matchTuples [regexp -all -inline $pattern $text]
     
    puts $matchTuples
    # H'22EF 22EF H'2354 2354 H'4BD4 4BD4 H'4C4B 4C4B H'4D52 4D52 H'4DC9 4DC9
    # \_________/ \_________/ \_________/ \_________/ \_________/ \_________/
    #  1st match   2nd match   3rd match   4th match   5th match   6th match
     
    puts [llength $matchTuples]
    # 12
     
    set numMatches [expr {[llength $matchTuples] / 2}]
    puts $numMatches
    # 6
     
    foreach {whole hex} $matchTuples {
       puts $hex
    }
    # 22EF
    # 2354
    # 4BD4
    # 4C4B
    # 4D52
    # 4DC9
    

    On the pattern

    Note that I’ve changed the pattern slightly:

    • Instead of [0-9A-Z]+, e.g. [0-9A-F]{4} is more specific for matching exactly 4 hexadecimal digits
    • If you insist on matching the &, then the last hex string (H'4DC9 in your input) can not be matched
      • This explains why you get 4D52 in the original script, because that’s the last match with &
      • Maybe get rid of the &, or use (&|$) instead, i.e. a & or the end of the string $.

    References

    • regular-expressions.info/Finite Repetition, Anchors
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Dear everybody who can help, I have this PHP > MongoDB problem, I want
I've seen this problem on the web, and all the suggested solutions aren't working
Hy everybody, Thanks in advance for your help. Here is my problem. I want
Hello everybody i have C++ tStringGrid I want to get string from specific cell
Hello everybody I am drawing dynamic table and I want to add header for
everybody! Could I ask you to help me to decode this JSON code: $json
Hi everybody and thanks for your time, I read filenames in a QList. This
Hi everybody. The problem: elcipse-3.5.0 (Galileo) spits with an error when I try to
I want to do the opposite of everybody ( laugh ) I start open-erp
O.K. Maybe I have asked something similar to this, but this is another problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.