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
On
-all -inlineFrom the documentation:
Thus to return all matches –including captures by groups– as a flat list in Tcl, you can write:
If the pattern has groups
0…N-1, then each match is anN-tuple in the list. Thus the number of actual matches is the length of this list divided byN. You can then useforeachwithNvariables to iterate over each tuple of the list.If
N = 2for example, you have:References
Sample code
Here’s a solution for this specific problem, annotated with output as comments (see also on ideone.com):
On the pattern
Note that I’ve changed the pattern slightly:
[0-9A-Z]+, e.g.[0-9A-F]{4}is more specific for matching exactly 4 hexadecimal digits&, then the last hex string (H'4DC9in your input) can not be matched4D52in the original script, because that’s the last match with&&, or use(&|$)instead, i.e. a&or the end of the string$.References