regex - awk split() function uses regular expression or exact string constant? -


if have ip=192.168.0.1 , call split(ip, myarray, "."), myarray contains "192" @ position 1, "168" @ position 2, "0" @ position 3 , "1" @ position 4.

my question why awk not interpreted "." "any character" regular expression?

what need if want make awk interpreted "." "any character" regular expression matching?

will behaviour consistent across awk implementations?

this dark corner of awk....

i had same doubt 5 years ago. submitted bug , talked developer of gawk, , got clear. "feature".

here ticket: https://lists.gnu.org/archive/html/bug-gawk/2013-03/msg00009.html

split(str, array, magic) 

for magic:

  • when use non-empty string (quoted "") "...", awk check length of string, if single char, used literal string (they call separator). if longer 1, treated dynamic regex.

  • when use static regex, means, in format /.../, no matter how long expression, treated regex.

that is:

"."  - literal "." (period) "["  - literal "[" "{"  - literal "{" ".*" - regex /./  - regex /whatever/ -regex 

if want awk treat .(period) regex metacharacter, should use split(foo,bar,/./) if split char, may have empty arrays, if want.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -