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. What is the regular expression for this string?

What is the regular expression for this string?

Scheduled Pinned Locked Moved Regular Expressions
regexquestiondatabase
5 Posts 4 Posters 24 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.
  • M Offline
    M Offline
    Member_15959121
    wrote on last edited by
    #1

    I am looking for the regular expression for the following.

    Microsoft.Sql/servers/*.*/databases

    That can match

    Microsoft.Sql/servers/some-text/databases
    Microsoft.Sql/servers/some--other-text/databases

    etc...

    The words

    "Microsoft.Sql/servers/"

    &

    "/databases"

    should be an exact match.. and where

    *.*

    can match any text.

    L J 2 Replies Last reply
    0
    • M Member_15959121

      I am looking for the regular expression for the following.

      Microsoft.Sql/servers/*.*/databases

      That can match

      Microsoft.Sql/servers/some-text/databases
      Microsoft.Sql/servers/some--other-text/databases

      etc...

      The words

      "Microsoft.Sql/servers/"

      &

      "/databases"

      should be an exact match.. and where

      *.*

      can match any text.

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

      Try this:

      Microsoft.Sql/servers/.*/databases

      The .* will match an character followed by any other character, so you may need to modify that if you want to exclude any specific characters (e.g. any that are not valid in path names). You can get yourself a free copy of Expresso Regular Expression Tool[^] which will help develop REs. [edit] As suggested by k5054 below, the RE should have anchors so it is restricted to the actual text starting at Microsoft and ending at databases.

      ^Microsoft.Sql/servers/.*/databases$

      [/edit]

      K 1 Reply Last reply
      0
      • L Lost User

        Try this:

        Microsoft.Sql/servers/.*/databases

        The .* will match an character followed by any other character, so you may need to modify that if you want to exclude any specific characters (e.g. any that are not valid in path names). You can get yourself a free copy of Expresso Regular Expression Tool[^] which will help develop REs. [edit] As suggested by k5054 below, the RE should have anchors so it is restricted to the actual text starting at Microsoft and ending at databases.

        ^Microsoft.Sql/servers/.*/databases$

        [/edit]

        K Offline
        K Offline
        k5054
        wrote on last edited by
        #3

        You might want to add anchors to that, too eg:

        ^Microsoft.Sql/servers/.*/databases$

        so you don't also match my-Microsoft.Sql/servers/some-text/databases.info

        Keep Calm and Carry On

        L 1 Reply Last reply
        0
        • K k5054

          You might want to add anchors to that, too eg:

          ^Microsoft.Sql/servers/.*/databases$

          so you don't also match my-Microsoft.Sql/servers/some-text/databases.info

          Keep Calm and Carry On

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

          Thanks, I forgot about those.

          1 Reply Last reply
          0
          • M Member_15959121

            I am looking for the regular expression for the following.

            Microsoft.Sql/servers/*.*/databases

            That can match

            Microsoft.Sql/servers/some-text/databases
            Microsoft.Sql/servers/some--other-text/databases

            etc...

            The words

            "Microsoft.Sql/servers/"

            &

            "/databases"

            should be an exact match.. and where

            *.*

            can match any text.

            J Offline
            J Offline
            jschell
            wrote on last edited by
            #5

            Member 15959121 wrote:

            Microsoft.Sql/servers/*.*/databases

            You are misusing the asterisk. It matches the preceding element only. which in this case is the forward slash. Moreover it matches zero or more. Which is probably not what you want. However you also said...

            "Microsoft.Sql/servers/" and "/databases" should be an exact match

            So the first attempt at a fix, which is not correct, would look like the following.

            (Microsoft.Sql/servers/)?.*/databases

            But that is limited then because it does not match the second expression. You might think the following is a good idea but do NOT do this. You should never create a regex in which everything is optional.

            (Microsoft.Sql/servers/)?.*(/databases)?

            You would need to use an or ('|') with 3 expressions (match first, match last, match all) which to me is way too confusing from the maintenance standpoint. It is not even clear to me if you have defined your match space. Presuming the following are NOT valid

            Microsoft.Sql/servers/xxx
            xxx/databases

            Then I would do the following (pseudo code)

            if match just: Microsoft.Sql/servers
            else if match just: /databases
            else match: Microsoft.Sql/servers/.*/databases

            But additionally note even the above matches the following which is probably not what you want.

            Microsoft.Sql/servers///\\&4xz /databases/servers/databases

            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