3

I'm attempting to write a script using the Android shell (with Busybox) to scan through some .xml files to extract information, however, I'm getting stuck on some optimization.

Shouldn't, for example,

(ax)b

match to

axbxc

It doesn't; when I try to execute this on Android (4.2.2, with Busybox 1.20.2, if it matters?).

echo axbxc > \sdcard\test.txt
grep "(ax)b" \sdcard\test.txt

returns nothing, while

grep "axb" \sdcard\test.txt

returns, as expected,

axbxc

Similarly, shouldn't

(?>ax)b

return axbxc as well? (This is the actual optimization I want to apply.)

What could be causing this problem? Additionally, does anyone know what regex engine Busybox uses, so that I can go and read up on it specifically?

1 Answer 1

4

To enable extended regular expressions in grep (and in busybox grep), you need to either use grep -E or use egrep (egrep is shortcut for grep -E).

I have tested this with busybox grep, and both methods work as expected and match your regex.

As for (?>ax)b - this would work only if you can use grep -P (support for Perl compatible regexes). However, busybox grep does not support this switch, so look-ahead and look-behind matches won't work.

Sign up to request clarification or add additional context in comments.

1 Comment

... Oh. Thanks. Well, I feel silly now. Do you by any chance know what regex engine Busybox uses?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.