How to use Regular Expressions for Searching

Use regular expressions to perform the search.  Expressions are case sensitive.
Search examples:


  1. .* matches any name.

  2. ab.* matches names that begin with the letters ab.

  3. .*10 matches names the end with 10

  4. ab.*10 matches names that begin with ab, and end with 10.

  5. .*NY.* matches names that have the string 'NY' as a substring (e.g. vm-NY-45, NYHost1).
Have more questions? Submit a request

Comments

  • Avatar
    David Parker

    I'm trying to use the ^ to exclude certain characters. Is this regex function supported?

  • Avatar
    Ben Fariello

    Hi David,

    It looks like the ^ regex to exclude characters is supported. For example, if you have several Fedora VMs: FedoraA, FedoraB, Fedora-1, and Fedora-2, you could search for

    Fedora[A-z]

    and find just the first two Fedora VMs, and if you search for

    Fedora[^A-z]

    you will find just the last two Fedora VMs.

    We do require that you escape some characters (e.g. the space character,, square brackets, etc.) in order to search for them, however. Could that be the issue?

     

    Thanks,

    -Ben Fariello

  • Avatar
    David Parker

    I was trying to do the ^ on a string, particularly 'NFSDB1' or a partial match not 'DB1'. I may have formatted the expression incorrectly, I'm no expert at regex.  I tried examples from some guide, but I don't have that handy. Can you help me out?

  • Avatar
    Ben Fariello

    Hi David,

    I'm not a regex expert myself, but I think this should be able to exclude any string that matches "DB1" anywhere in the string:

    ^((?!DB1).)*$

    Does that help you out?

  • Avatar
    Ben Personick

    David,

      The guide above may be a bit unclear, and Regex itself can at times be a bit obtuse.

      Note that when using the general search function by default we will match anywhere that string occurs whether there are characters before or after it.

     

    The ^ (carrot) character explicitly matches the beginning of a line, and the $ (Dollar Sign) will explicitly match the end of a line.

     

    So, if you have the VMs "ABCd-123" "123-abc" "1a_Bc23" and "Bc22a" then here are examples of searches for them

    if you type "abc" in the search box, you will see: "ABCd-123" and "123-abc"

    if you type "23" in the search box you will see: "ABCd-123" "123-abc" and "1a_Bc23"

    if you type "^[ab]" in the search box you will see: "ABCd-123" and "Bc22a"

    if you type "3$" in the search box you will see: "ABCd-123" and "1a_Bc23"

    if you type "d$" in the search box you will get no results

     

  • Avatar
    David Parker

    Perfect! Awesome, thank you very much!

  • Avatar
    Ben Personick

    David,

      The guide above may be a bit unclear, and Regex itself can at times be a bit obtuse.

      Note that when using the general search function by default we will match anywhere that string occurs whether there are characters before or after it.

     

    The ^ (carrot) character explicitly matches the beginning of a line, and the $ (Dollar Sign) will explicitly match the end of a line.

     

    So, if you have the VMs "ABCd-123" "123-abc" "1a_Bc23" and "Bc22a" then here are examples of searches for them

    if you type "abc" in the search box, you will see: "ABCd-123" and "123-abc"

    if you type "23" in the search box you will see: "ABCd-123" "123-abc" and "1a_Bc23"
    if you type "^[ab]" in the search box you will see: "ABCd-123" and "Bc22a"
    if you type "3$" in the search box you will see: "ABCd-123" and "1a_Bc23"
    if you type "d$" in the search box you will get no results

    To exclude a set of characters you can wrap it in a special series of characters as Ben F shows in his previous post

    ((?!XXX).)*  the XXX will be whatever string you would like to exclude.

    So, if you have the VMs "ABCd-123" "123-abc" "1a_Bc23" and "Bc22a" then here are examples of searches for them

    if you type "a((!?d).)" in the search box, you will see nothing
    if you type "((!?d).)*3$" in the search box you will see: "1a_Bc23"
    if you type "((!?-).)
    " in the search box you will see: "1a_Bc23" and "Bc22a"
     

    I hope that helps you create useful regular expressions you can utilize beyond your needs today.

    Thanks,

    Ben Personick