Login
|
Signup
langref.org
-
python
,
fsharp
,
fantom
,
groovy
...
add..
all
clojure
cpp
csharp
erlang
go
java
ocaml
perl
php
ruby
scala
Home
All
Solved
Unsolved
Strings
Numbers
Regex
Lists
Maps
Structure
Files
Dates
OOP
Networking
XML
Algorithms
Misc
Parallel
View Problem
Regex
Matching
Check if a string matches a regular expression
Display
"ok"
if
"Hello"
matches
/[A-Z][a-z]+/
python
found = re.match(r'[A-Z][a-z]+', 'Hello')
if found:
print 'ok'
found = re.match(r'[A-Z][a-z]+', 'Hello')
if found:
print 'ok'
fsharp
if (Regex.IsMatch("Hello", "[A-Z][a-z]+")) then printfn "ok"
#light
open System
open System.Text.RegularExpressions
if (Regex.IsMatch("Hello", "[A-Z][a-z]+")) then printfn "ok"
fantom
if (Regex<|[A-Z][a-z]+|>.matches("Hello"))
echo("ok")
class Solution1497
{
Void main()
{
if (Regex<|[A-Z][a-z]+|>.matches("Hello"))
echo("ok")
}
}
groovy
if ("Hello" =~ /[A-Z][a-z]+/) println 'ok'
if ("Hello" =~ /[A-Z][a-z]+/) println 'ok'
groovy
1.6.1+
if ("Hello".find(/[A-Z][a-z]+/)) println 'ok'
if ("Hello".find(/[A-Z][a-z]+/)) println 'ok'
groovy
1.6.1+
// with precompiled regex
def regex = ~/[A-Z][a-z]+/
if ("Hello".find(regex)) println 'ok'
// with precompiled regex
def regex = ~/[A-Z][a-z]+/
if ("Hello".find(regex)) println 'ok'
groovy
1.6.1+
// with precompiled regex
def regex = ~/[A-Z][a-z]+/
if ("Hello".matches(regex)) println 'ok'
// with precompiled regex
def regex = ~/[A-Z][a-z]+/
if ("Hello".matches(regex)) println 'ok'
groovy
if ("Hello".matches("[A-Z][a-z]+")) println 'ok'
if ("Hello".matches("[A-Z][a-z]+")) println 'ok'
haskell
import Text.Regex.Posix
main = if "Hello" =~ "[A-Z][a-z]+" then putStrLn "OK" else return ()
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
...)