1. #1
    Administrator
    Windows Update Instructor
    Security Analyst

    Join Date
    Oct 2014
    Posts
    15,638

    RegEx - Anyone know how to do this?

    I'm not very good at RegEx. I know the basics but have run into a need. Any idea how to write a RegEx that will always extract the parts in Red? Treat each line below as a separate record.

    These are notes in a comment field. It will have text and numbers 38888837773 and also a combination of them like 01-645
    Sometimes it will be in the middle like 17-1790. There is always a dash between the numbers that we want.
    We can have scenarios where there are numbers followed by a space followed by what we want like 3838373737833893 27-378
    51-201 and sometimes the number will be right at the beginning like this.
    38373737337 37-298 or like this.
    51-072 3938383838 or like this.

    Any help would be extremely appreciated. Thank you.


    • Ad Bot

      advertising
      Beep.

        
       

  2. #2
    Tekno Venus's Avatar
    Join Date
    Jul 2012
    Location
    UK
    Age
    19
    Posts
    5,728
    • specs System Specs
      • Manufacturer:
        Custom Built
      • Motherboard:
        ASUS Z170I ITX
      • CPU:
        Intel Core i7 6700K
      • Memory:
        16GB DDR4
      • Hard Drives:
        500GB Samsung 850 EVO, 2TB Seagate HDD
      • Power Supply:
        450W Corsair SFX
      • Case:
        Silverstone SG13 ITX
      • Cooling:
        Corsair H60i
      • Display:
        Dell U2715H - 2160x1440 27 inch
      • Operating System:
        Windows 10 Pro x64

    Re: RegEx - Anyone know how to do this?

    Will this work for you?

    Code:
    (\d)*-(\d)*


  3. #3
    Administrator
    Windows Update Instructor
    Security Analyst

    Join Date
    Oct 2014
    Posts
    15,638

    Re: RegEx - Anyone know how to do this?

    It works perfectly!!!! Thank you so much.

  4. #4
    AceInfinity's Avatar
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,712

    Re: RegEx - Anyone know how to do this?

    If the first 2 digits is always a length of 2 and you want to ensure that you have digits after the '-' you should change it to this:
    Code:
    \d{2}-\d+
    \d* can match 0 or more digits so that may not be entirely suitable.
    BrianDrab and Tekno Venus say thanks for this.
    \n\n

    Automation Programmer
    Development Site: aceinfinity.net

Similar Threads

  1. RegEx (Regular Expression) issue
    By maki in forum Programming
    Replies: 6
    Last Post: 11-08-2017, 12:24 PM
  2. Regex BBCode to WYSIWYG RichText Format
    By AceInfinity in forum Programming
    Replies: 4
    Last Post: 07-29-2012, 08:47 PM

Log in

Log in