'How to check if a string only contains certain characters in scala [closed]

How to check whether a string only contains certain characters, say "a" and "b" in Scala? I found several resources online, they are using regex. For Scala, most of them talked about the findAllIn or findFirstIn function. But I would like to have something that returns true or false.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source