What is regex?

Did you mean the opposite? Because Python, Ruby, Javascript, Perl, all of them have RegEx in their standard libraries. Could you point some mainstream scripting language of the last 20 years that do not have RegEx in their standard library?

Yes, you could use regular expressions in such case. However, the number of different formats for printf is relatively limited, their structure is very simple, and each of them basically needs to be treated in a different way, so I am not sure if that code uses RegEx inside it. Anyway, it is not an example of the use of RegEx but of an standard library method that may be using RegEx inside it.

It is a compact way, and after you learn/master them, it is a very easy way to search for certain patterns. However, they cannot represent every possible pattern (the theory of formal languages very clearly specifies what are their limitations) and it is common to find people criticizing their readability (I often write comments above them explaining them because, otherwise, months later I will have a hard time remembering what they were supposed to parse).

Sorry, I am not sure I understand which example you are asking me to do.

1 Like