-1
set vv "abc 123 456 "

regexp {abc[\s][\d]+[\s][\d]+} $vv 
1
regexp {abc[\s][\d]+[\s][\d]+(?! )} $vv 
1

Should return 0, as the line contains extra space at the end or extra characters.

From a list of lines, i am trying to know which lines have space at the end and which do not.

lines can be of any format, for instance, i need to extract line 1 and 3 but not 2 and 4.

  1. "abc 123 456"
  2. "abc 123 456 abc 999"
  3. "xyz 123 999"
  4. "xyz 123 999 zzz 222"

5 Answers5

1

You could use a repeating pattern matching a space and digits to make sure that the line ends with digits only:

^abc(?: \d+)+$

Regex demo

Or a bit broader match using word characters \w if the lines can be of any format:

^\w+(?: \w+)+$

Regex demo

The fourth bird
  • 154,723
  • 16
  • 55
  • 70
0

Not sure about TCL regex, but I think you have to add an anchor:

abc\s\d+\s\d+$
Toto
  • 89,455
  • 62
  • 89
  • 125
0

The regular express would be {^abc.*\d$} -- a digit followed by the end of the string.

% regex {^abc.*\d$} $vv
0

The glob pattern would be {abc*[0-9]}

% string match {abc*[0-9]} $vv
0
% string match {abc*[0-9] } $vv
1
glenn jackman
  • 238,783
  • 38
  • 220
  • 352
0

It can be summarized as ending of line ($) proceeding by words(\w).

puts [regexp {\w$} $vv]

Drektz
  • 95
  • 10
0

If all you need is to find out if a line ends with a space or not, use this for a regex:

\s$
Mr Lister
  • 45,515
  • 15
  • 108
  • 150