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 8072363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:59:41+00:00 2026-06-05T13:59:41+00:00

I am using RegEx to assert the response of an API call, but it’s

  • 0

I am using RegEx to assert the response of an API call, but it’s currently a little too ‘greedy’ and ends up matching all kinds of responses. The RegEx bits are needed since the actual IDs in the response will be different each time.

The RegEx assertion is this:

{data:\[{"name":"Mat","~id":"(.*)"},{"name":"Laurie","~id":"(.*)"}\]},"something":true}

Which matches this correct response:

{data:[{"name":"Mat","~id":"4fd5ec146fc2ee0fff234234"},{"name":"Laurie","~id":"4fd5ec146fc2ee0fff234227"}]},"something":true}

as well as this incorrect response:

{data:[{"name":"Mat","~id":"4fd5ec146fc2ee0fff234234"},{"name":"Laurie","~id":"4fd5ec146fc2ee0fff234227"},{"name":"John","~id":"4fd5ec146fc2ee0fff234237"},{"name":"Paul","~id":"4fd5ec146fc2ee0fff234238"},{"name":"George","~id":"4fd5ec146fc2ee0fff234239"}]},"something":true}

The second (.*) is not just matching the ID of the second item, but it’s matching the ID and all the other unwanted objects.

So I guess I need to make my RegEx be a little more strict when it comes to the ~id fields. Since the IDs will always be 24 hex characters, I’d like to replace the (.*) with something more appropriate.

  • I am writing this in Go, and therefore using Go’s RegExp package.
  • And am using http://regexpal.com/ to test the RegEx
  • 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-05T13:59:42+00:00Added an answer on June 5, 2026 at 1:59 pm

    You can use [^"]*, [^"]{24} or [0-9a-fA-F]{24} instead of .* for your ID fields.

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

Sidebar

Related Questions

I'm playing with using Regex to modify Twitter posts. I'm currently attempting to trim
I am using regex ^(([0-9])|([0-1][0-9])|([2][0-3])):(([0-9])|([0-5][0-9]))$ for time. It is very good regex but when
I'm using regex to match all non-quoted property names in my json files. Eclipse
Is it possible using Regex.Replace to match a string, but only replace a portion
Here my problem: @Assert\Regex( * pattern=/^[A-Za-z0-9][A-Za-z0-9\]*$/, * groups={creation, creation_logged} * ) I'm using the
How to escape all regex characters automatically using built-in .NET mechanism or something like
How would I go about using regex to add a static string to all
How to get all matches from a string using regex? I have a string:
I am trying to clean up user submitted comments in PHP using regex but
I originally asked a question along these lines using Regex but was recommended to

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.