The value in Regular Expressions (RegEx) for non-developers

0


Life is made from the matches we seek and attempt to find along the way.

Whether you are trying to find an apartment that has all of your most-wanted attributes or you are swiping across profiles to match with someone on the apps – most of us know the feeling of searching for something specific.

Regular Expressions, commonly known as RegEx, are also focused on the specifics and they are a powerful tool for searching and manipulating text, with a history dating back to the 1950s.

If you aren’t a developer, most times you interact with RegEx is probably attempting to “find and replace” a word or phrase in your documents or typing a search prompt or question into a Google or Microsoft search engine.

However, RegEx can be extremely useful to define search patterns within strings of text, making them invaluable for tasks like Content Scanning within BetterCloud.

RegEx in the real world

Below are five ways to illustrate how RegEx can applied to real-world scenarios and document security:

1. Credit Card Numbers

Credit card numbers typically follow specific patterns. Here are some common RegEx patterns for different card types:

  • Visa: ^4[0-9]{12}(?:[0-9]{3})?$
  • MasterCard: ^5[1-5][0-9]{14}$
  • American Express: ^3[47][0-9]{13}$
  • Discover: ^6(?:011|5[0-9]{2})[0-9]{12}$

Learning Tip: ^ indicates the start of your string, and the first number in each example above refers to the Bank Identification Number of each financial institution. Visa cards begin with four digits for their BIN, and Amex uses three digits.

2. Social Security Numbers (SSN)

SSNs in the United States follow the pattern XXX-XX-XXXX. The RegEx for this would be:

Unset:

^\d{3}-\d{2}-\d{4}$

3. Proximity Searches

To find words near each other, you can use a combination of lookaheads and lookbehinds. For example, to find the word “Social” near a string that looks like an SSN:

Unset:

Social.*?\d{3}-\d{2}-\d{4}|\d{3}-\d{2}-\d{4}.*?Social

This pattern looks for “Social” followed by an SSN or an SSN followed by “Social”.

4. Credit Near Numbers (Credit Card)

To find the word “credit” near a credit card number:

Unset:

credit.*?\b(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12})\b|\b(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12})\b.*?credit

This pattern looks for “credit” followed by a credit card number or a credit card number followed by “credit”.

5. Internal File Indicators

To identify content that indicates an internal file, you might look for phrases like “internal use only” or “confidential”. Here’s a simple example:

Unset:

\b(internal use only|confidential|do not share)\b

Putting It All Together

Now let’s combine all of our five RegEx examples above into one. For example, to search for any of the above patterns in a file, we could use the following:

Unset:

(Social.*?\d{3}-\d{2}-\d{4}|\d{3}-\d{2}-\d{4}.*?Social|credit.*?\b(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12})\b|\b(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12})\b.*?credit|\b(internal use only|confidential|do not share)\b)

Leveraging custom RegEx with BetterCloud

If you are interested in learning more about RegEx and how to best leverage its capabilities within BetterCloud, request a demo to see more of what BetterCloud can do for your company. 

Want to go even deeper with your RegEx knowledge? Check out the resources our technical teams have pulled together for you below:



Source link

You might also like