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: | 498 |
Nodes: | 16 (2 / 14) |
Uptime: | 09:15:15 |
Calls: | 9,822 |
Calls today: | 1 |
Files: | 13,757 |
Messages: | 6,190,747 |