Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
Sponsors
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • A single character of: a, b or c
    [abc]
  • A character except: a, b or c
    [^abc]
  • A character in the range: a-z
    [a-z]
  • A character not in the range: a-z
    [^a-z]
  • A character in the range: a-z or A-Z
    [a-zA-Z]
  • Any single character
    .
  • Alternate - match either a or b
    a|b
  • Any whitespace character
    \s
  • Any non-whitespace character
    \S
  • Any digit
    \d
  • Any non-digit
    \D
  • Any word character
    \w
  • Any non-word character
    \W
  • Non-capturing group
    (?:...)
  • Capturing group
    (...)
  • Zero or one of a
    a?
  • Zero or more of a
    a*
  • One or more of a
    a+
  • Exactly 3 of a
    a{3}
  • 3 or more of a
    a{3,}
  • Between 3 and 6 of a
    a{3,6}
  • Start of string
    ^
  • End of string
    $
  • A word boundary
    \b
  • Non-word boundary
    \B

Regular Expression
Processing...

Test String

Code Generator

Generated Code

$re = '/(?:[a-zA-Z\'-]+[^a-zA-Z\'-]+){0,4}(\w*|\s|^)comm[a-zA-Z0-9]*(?:[^a-zA-Z\'-]+[a-zA-Z\'-]+){0,4}/m'; $str = '"​Wellbeing Checklist- how to reduce absenteeism in the winter monthsDid you know that in 2015/2016, 30.4million working days were lost due to illness? Not only does the cost of lost days impact the UK Economy (£16.6bn in 2015) but it also raises a flag as to why staff are taking all this time off!When Vitamin D was flagged as a potential to reduce colds and other viruses it instantly trended on Twitter – a sure sign that we have a real interest in getting better quickly!We spoke to the experts at Personal Group and asked them to create a wellbeing checklist for HR professionals. So, if time off is impacting you, read on and get to the bottom of why your staff are taking so much time off and see how to put a plan in place to make sure that when they are off, it is for the right reasons!1) Understand the issues.Back to work interviews are good but there is a risk that staff aren’t telling you the real reasons they are off. What you really need is a way of predicting why these sick days are being taken so you can make sure that there is something in place to eliminate any need for unnecessary days off. Look back at your annual surveys, are there any issues trending that might lead to stress or worry for staff? A HR Hub that can delve into stats will allow you see just how many times people are looking at their EAP programme and what issues are most prevalent. Take this information and make it work for you. Does your Health and Wellbeing programme really tick all the boxes? If you are seeing a rise in people asking for advances in pay, then communicate details of the benefits you have in place that might help combat that worry, stress and other issues before it manifests itself into something worse.2) Culture is key“If everyone else is taking days off, then why shouldn’t I?”. It might be the case that staff who have been working for you for a long time are more lapsed in their attendance. Or, if you have flexible working, if people are not in the office most of the time staff could try and take days off in the hope that it won’t be noticed. This is where you need to lead by example. Celebrate those who have had the best attendance and reaffirm company attendance policies. Take time to see if staff know your sickness policy and that Line Managers are aware of how to deal with absenteeism from the odd sick day, right down to long term absence from the office. It is also important that you communicate the employee benefits on offer that can help staff remain healthy and happy at work. Showing people that these things are in place will show that you care and make your staff happier to show up to the office. If they are feeling stressed or worried and have nowhere to turn, then it might be easier for them to hide at home.3) Set a challengeIf you want a healthy and happy workforce then you should be coming up with ways to engage staff so that they want to be in the office. It could be helping with major lifestyle changes such as Stop Smoking workshops, right down to giving every member of staff a Fitbit. After all, who doesn’t love a bit of healthy competition? Plus, you can celebrate the success of staff once they reach health and wellness milestones! These initiatives can bring staff together and is a good way to make sure that you are encouraging your staff to be healthy as well as showing you care about their wellbeing. A change in lifestyle could be the solution to your problem. Incorporating interactive initiatives into your health and wellbeing programme is not only fun for staff but you will be able to see the results. Wellbeing days and workshops are a great way to form a mutual interest amongst all staff. This is a powerful engagement tool with fitness as a positive consequence."'; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php