View Problem

Check if a string matches a regular expression

Display "ok" if "Hello" matches /[A-Z][a-z]+/
DiskEdit
python
found = re.match(r'[A-Z][a-z]+', 'Hello')
if found:
print 'ok'
ExpandDiskEdit
fsharp
if (Regex.IsMatch("Hello", "[A-Z][a-z]+")) then printfn "ok"
ExpandDiskEdit
fantom
if (Regex<|[A-Z][a-z]+|>.matches("Hello"))
echo("ok")
DiskEdit
groovy
if ("Hello" =~ /[A-Z][a-z]+/) println 'ok'
DiskEdit
groovy 1.6.1+
if ("Hello".find(/[A-Z][a-z]+/)) println 'ok'
DiskEdit
groovy 1.6.1+
// with precompiled regex
def regex = ~/[A-Z][a-z]+/
if ("Hello".find(regex)) println 'ok'
DiskEdit
groovy 1.6.1+
// with precompiled regex
def regex = ~/[A-Z][a-z]+/
if ("Hello".matches(regex)) println 'ok'
DiskEdit
groovy
if ("Hello".matches("[A-Z][a-z]+")) println 'ok'
DiskEdit
haskell
import Text.Regex.Posix
main = if "Hello" =~ "[A-Z][a-z]+" then putStrLn "OK" else return ()

Submit a new solution for python, fsharp, fantom, groovy ...
There are 16 other solutions in additional languages (clojure, cpp, csharp, erlang ...)