I got concerned by "achored", tested
expr "A%aB%bC%cX" : "%[^auUlLcCsS%]"
and got a "0" returned, which is not what you want.
expr "A%aB%bC%cX" : ".*\(%[^auUlLcCsS%]\)"
returns "%b", though. So your mileage may vary.
$ echo "A%aB%bC%cX" |
awk '{ print match($0,/%[^auUlLcCsS%]/)
print substr($0,RSTART,RLENGTH) }'
5
%b
I want to do some regexp matches on strings with expr, a tool I rarely
used, and I'm puzzled about its correct usage for the intended purpose,
If possible I'd want either the substring or the index of the match in
the string and I thought that expr might serve as a light-weight tool
to avoid grep or awk.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 112 |
Nodes: | 8 (1 / 7) |
Uptime: | 218:10:12 |
Calls: | 2,466 |
Calls today: | 1 |
Files: | 8,608 |
Messages: | 1,881,102 |