re icon indicating copy to clipboard operation
re copied to clipboard

Option request: Wrap capture groups with string or character

Open ohaal opened this issue 13 years ago • 2 comments

Specify wrap char/string: -e "."

To auto escape occurences of wrap char/string: -a

In use:

$ ifconfig | re -e "\"" -g "(?P<IF>eth\d+).+?inet addr:(?P<IP>[\d.]+)"
IF="eth0", IP="10.0.0.100", IF="eth1", IP="10.0.0.101"

ohaal avatar May 10 '12 09:05 ohaal

Do you have an example of when this would be useful? You could potentially do something like this:

$ ifconfig | re -g "(?P<IF>eth\d+).+?inet addr:(?P<IP>[\d.]+)" | re 's/=([^,]+)/="${1}"/'
IF="eth0", IP="10.0.0.200"

prasmussen avatar May 25 '12 22:05 prasmussen

$ re -dr ", " "([^ .][^.]*)" <<< "hello world, foo bar. baz qux."
hello world, foo bar, baz qux

vs.

$ re -e -dr ", " "([^ .][^.]*)" <<< "hello world, foo bar. baz qux."
"hello world, foo bar", "baz qux"

(if default char/string is " when using -e option with no param)

ohaal avatar May 29 '12 13:05 ohaal