Regex Search Help!



  • New to using regex for searches. Looking for a way to search and select the value of an item in the following format: “Number”:“12345”,
    I have tried the following but it only selects the title and not the value: “Number”:"*
    And if I try this: “Number”:"*, it doesn’t return any results.
    I thought the wildcard would suggest anything could be between the " and the ,

    Any suggestions on how I could do this search is appreciated.

    Thanks



  • Try
    “Number”:".*,



  • @Aaron-Laws said in Regex Search Help!:

    “Number”:“12345”,

    Certainly the reply above works, however to maintain a tighter control over what is selected I would change the * in your regex to \d+ which means as many digits as can be found together, or if ALWAYS 5 digits then \d{5} which means exactly 5 digits.

    I n your regex the * is not the wild card but refers to 0 or more of the previous character. See
    http://rexegg.com/regex-quickstart.html

    Terry



  • Thank you that works well. What if I wanted it go until a comma is found? (next value) instead of only one number in case there are more than one.



  • @Aaron-Laws said in Regex Search Help!:

    What if I wanted it go until a comma is found?

    If it could be ANY character not just a number then @Nick-Brown regex will work. His works even if ZERO characters until the comma.

    Please be careful with the quotes as what you have in the data and what is represented here could be different. The forum formatter can alter some characters entered by keyboard. Its important if showing examples to enter them, then select them all and use the </> button above to encapsulate them in code to prevent changes being made.

    Terry



  • @Nick-Brown 's regex is problematic for at least 2 more reasons:

    • it does a greedy search rather than a minimal search, meaning that it will match something like "Number":"12345","23456","34567", fully, not stopping after only matching “one number”, which seems to be what the OP desires

    • in conjunction with the first point, without specification of whether or not the . should match newlines, this regex could potentially match a lot of lines and a lot of data!


Log in to reply