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'
DiskEdit
clojure
(if (re-matches #"[A-Z][a-z]+" "Hello")
(println "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")
ExpandDiskEdit
java
if ("Hello".matches("[A-Z][a-z]+")) {
System.out.println("ok");
}
ExpandDiskEdit
cpp C++/CLI .NET 2.0
if ((gcnew Regex("[A-Z][a-z]+"))->IsMatch("Hello")) Console::WriteLine("ok");
ExpandDiskEdit
cpp C++/CLI .NET 2.0
if (Regex::IsMatch("Hello", "[A-Z][a-z]+")) Console::WriteLine("ok");
ExpandDiskEdit
cpp C++/CLI .NET 2.0
Regex^ rx = gcnew Regex("[A-Z][a-z]+");
if (rx->IsMatch("Hello")) Console::WriteLine("ok");
ExpandDiskEdit
cpp
cmatch what;
if (regex_match("Hello", what, regex("[A-Z][a-z]+")))
cout << "ok" << endl;
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'
ExpandDiskEdit
erlang
String = "Hello", Regexp = "[A-Z][a-z]+",
is_match(String, Regexp) andalso (begin io:format("ok~n"), true end).
DiskEdit
erlang 12B3+
case re:run("Hello", "[A-Z][a-z]+") of {match, _} -> ok end.

Submit a new solution for python, clojure, fsharp, fantom ...
There are 9 other solutions in additional languages (csharp, go, haskell, ocaml ...)