49 people like it.

Perl Style "Regex Matches?" operator

Perl Style "Regex Matches?" operator

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
//Perl style regex match operator, eg: foo =~ "foo"
let (=~) target regex =
  System.Text.RegularExpressions.Regex.IsMatch(target, regex)


//Example
let x = "lool";
if x =~ "lo+l" then
  printf "matched"
else
  printf "nope"
val target : string
val regex : string
namespace System
namespace System.Text
namespace System.Text.RegularExpressions
Multiple items
type Regex =
  new : pattern:string -> Regex + 1 overload
  member GetGroupNames : unit -> string[]
  member GetGroupNumbers : unit -> int[]
  member GroupNameFromNumber : i:int -> string
  member GroupNumberFromName : name:string -> int
  member IsMatch : input:string -> bool + 1 overload
  member Match : input:string -> Match + 2 overloads
  member Matches : input:string -> MatchCollection + 1 overload
  member Options : RegexOptions
  member Replace : input:string * replacement:string -> string + 5 overloads
  ...

Full name: System.Text.RegularExpressions.Regex

--------------------
System.Text.RegularExpressions.Regex(pattern: string) : unit
System.Text.RegularExpressions.Regex(pattern: string, options: System.Text.RegularExpressions.RegexOptions) : unit
System.Text.RegularExpressions.Regex.IsMatch(input: string, pattern: string) : bool
System.Text.RegularExpressions.Regex.IsMatch(input: string, pattern: string, options: System.Text.RegularExpressions.RegexOptions) : bool
val x : string

Full name: Script.x
val printf : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printf

More information

Link:http://fssnip.net/32
Posted:4 years ago
Author:fholm
Tags: regex , regexp , operator , operators