Python · Regular Expressions

What does this print? ``` import re print(re.sub(r"[Jj]ava", "Python", "Java and java")) ```

Answer locked. Get the free KnowCard app to reveal it — plus spaced-repetition review so it actually sticks.

Get it on App StoreGet it on Google Play

This is one card from the KnowCard library — thousands more across SAP, Linux, Python and more. In the app you get the answer, AI explanations, and cards that come back right before you would forget them. Free to start on iOS, Android or the web.

More in Regular Expressions

Greedy .* vs lazy .*? — what's the difference and when does it bite you?
Why should regex patterns almost always be written as raw strings r"..." instead of plain strings?
What does this print? ``` import re print(re.match(r"Python", "I love Python")) ```
re.match vs re.search vs re.fullmatch — what does each require of where the pattern sits in the string?
What does this print? ``` import re print(re.findall(r"P[Yy]thon", "Python or PYthon")) ```
What does this print? ``` import re print(re.findall(r"P([Yy])thon", "Python and PYthon")) ```

Start learning today

Free to start — download the app or use it in your browser.

Get it on App StoreGet it on Google Play