4 people like it.

String to Int and String

Regex String and Int, e g : "qwe123" -> "qwe" and 123, "qwe" -> "qwe", 123 -> 123

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
let IntAndString value =    
    let (|Match|_|) pattern input =
        let m = Regex.Match(input, pattern) in
        if m.Success then Some ([ for g in m.Groups -> g.Value ]) else None
    match value with
        | Match @"((?>\d+))(\w+)" x -> Some(x)              
        | Match @"((?>\d+))" x      -> Some(x @ ["items"])  
        | Match @"(\w+)" x          -> Some(x)             
        | _                         -> None
val IntAndString : value:'a -> string list option

Full name: Script.IntAndString
val value : 'a
val pattern : 'b
val input : 'c
val m : obj
union case Option.Some: Value: 'T -> Option<'T>
val g : obj
union case Option.None: Option<'T>
active recognizer Match: 'b -> 'c -> 'd list option
val x : string list

More information

Link:http://fssnip.net/8A
Posted:6 years ago
Author:nCdy
Tags: string regex