Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Regular Expressions
  4. Finding a specific number in a string.

Finding a specific number in a string.

Scheduled Pinned Locked Moved Regular Expressions
questiontutorial
3 Posts 2 Posters 10 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 10834952
    wrote on last edited by
    #1

    I can find plenty of examples of how to find a number in a string, but now how to find a number preceded by a specific string. Like...

    [2020-07-24_184102][ACF11B2Y90][CCT]_Cycle0001.csv

    How can I say "give me the number that follows the text 'Cycle'?"

    L 1 Reply Last reply
    0
    • U User 10834952

      I can find plenty of examples of how to find a number in a string, but now how to find a number preceded by a specific string. Like...

      [2020-07-24_184102][ACF11B2Y90][CCT]_Cycle0001.csv

      How can I say "give me the number that follows the text 'Cycle'?"

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      /Cycle\d+\.csv/

      You can work these out for yourself quite quickly at RegExr: Learn, Build, & Test RegEx[^]

      U 1 Reply Last reply
      0
      • L Lost User

        /Cycle\d+\.csv/

        You can work these out for yourself quite quickly at RegExr: Learn, Build, & Test RegEx[^]

        U Offline
        U Offline
        User 10834952
        wrote on last edited by
        #3

        Thanks Richard. I finally ended up working out the following:

        (?<=Cycle)\d{4}

        This returns the '0001' like I want. I actually came close to working this out before posting, but failed to notice that I had a space before the \d. Duh.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups