Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8186063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:04:06+00:00 2026-06-07T02:04:06+00:00

In the following example code, I filter a list of strings on a regular

  • 0

In the following example code, I filter a list of strings on a regular expression, knowing that there can only be a single entry that will match that string. I then use the same match string to get 2 grouped values out of the single remaining value.

let input = ["aaaa bbbb";"aaabbbb";"cccc$$$$";"dddddda";" "] 

let ValuesOfAB (input: string list) = 
    let matchString = "(?<a>\w+)\s(?<b>\w+)"

    let value = input |> List.filter (fun line -> Regex.Matches(line, matchString).Count <> 0) 
                      |> List.head
    (Regex.Matches(value, matchString).[0].Groups.["a"].Value, Regex.Matches(value, matchString).[0].Groups.["b"].Value)

let a = ValuesOfAB input

Is there a better way where I don’t have to use Regex.Matches on the same string again for a second time to get the values I wish to return?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:04:07+00:00Added an answer on June 7, 2026 at 2:04 am

    Use List.pick:

    let input = ["aaaa bbbb";"aaabbbb";"cccc$$$$";"dddddda";" "] 
    
    let valuesOfAB (input: string list) = 
        let matchString = "(?<a>\w+)\s(?<b>\w+)"
        let v = input |> List.pick (fun line -> let m = Regex.Match(line, matchString)
                                                if m.Success then Some m else None)
        v.Groups.["a"].Value, v.Groups.["b"].Value
    
    let a = valuesOfAB input
    

    Explanation:

    You would like to match the first string in the list and return Match object in order that you don’t have to run Regex again. List.pick fits the task quite well.

    With each string, you need to match at least once so Regex.Match and Match.Success is enough for the purpose.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a method that can be used with each to filter array elements
I have the following example code: $dataProvider = new CActiveDataProvider('firstTable', array('criteria' => array( 'select'
Please consider the following example code (from the lm doc): ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14) trt
The following Microsoft example code contains the following: <Grid> ... <Border Name=Content ... >
In the following code example how do the user/userParam references relate to the Customer
Please forgive the verbosity of the following code example. Using Delphi 2009, I created
Possible Duplicate: C programming division in the following code example the result should yield
Consider following SWT code example: http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet151.java?view=co How can I separate the inline defined class?
In the following (working) code example, the templated register_enum() function is used to iterate
I've got following (simplified for example purpose) code and it works: void log(const string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.