1 people like it.

Test string is all UpperCase 2

There is another "All Uppercase" snippet that does two searches - one to verify that there's at least one upper case letter and one to make sure there are no lowercase letters. "---D" is "uppercase" but "---" is not. I wanted to duplicate that behavior even though it seems a bit questionable, but do it in one regex search. The underappreciated lookahead features of RegEx allow this sort of thing - scanning forward and then rescanning forward so I use that here

1: 
2: 
3: 
4: 
5: 
open System
open System.Text.RegularExpressions

let isUppercase (input:string):bool =
     Regex.Match(input, "(?=^[^a-z]*$).*[A-Z]").Success
namespace System
namespace System.Text
namespace System.Text.RegularExpressions
val isUppercase : input:string -> bool

Full name: Script.isUppercase
val input : string
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = String

Full name: Microsoft.FSharp.Core.string
type bool = Boolean

Full name: Microsoft.FSharp.Core.bool
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

--------------------
Regex(pattern: string) : unit
Regex(pattern: string, options: RegexOptions) : unit
Regex.Match(input: string, pattern: string) : Match
Regex.Match(input: string, pattern: string, options: RegexOptions) : Match
Raw view Test code New version

More information

Link:http://fssnip.net/7UI
Posted:6 years ago
Author:Darrell Plank
Tags: regex , regular expression , string , string matching , upper case