Remember that because our regex pattern is entirely inside a bracket expression, the string doesn’t need to meet all of the requirements-just any of them. l3rn-antin0_1 is a match because it is 13 characters long (within the minimum and maximum character limits of 3 and 16) and includes a combination of lowercase characters, numbers, and the special characters of an underscore and a hyphen.
![filelocator pro regular expression tutorial filelocator pro regular expression tutorial](https://www.saashub.com/images/app/screenshots/15/4647f5277ff4/landing-medium.jpg)
The 123 string is a match because it meets the minimum requirement of 3 characters, and the characters are all numbers. This regex is looking for any string between 3 and 16 characters that starts and ends with a combination of lowercase characters, the numbers 0–9, and the special characters of an underscore and a hyphen. Because our bracket expression ( ) will match any string that includes any combination of lowercase letters between a and z, any number between 0 and 9, and the special characters of an underscore or a hyphen, this quantifier means that this string has to be between 3 and 16 characters. This means that we want to find the preceding string pattern a minimum of 3 times and a maximum of 16 times. You'll notice that we didn't include the pattern. So in our “Matching a Username” regex, the string must start and end with something that matches the pattern. Just as with the ^ character, it can be preceded by an exact string or a range of possible matches. The $ anchor signifies a string that ends with the characters that precede it. This is because a regex is case-sensitive.Ī range of possible matches, displayed using bracket expressions. This could be in one of two formats:Īn exact string match, such as ^The, where the strings "The" or "The person" match, but "the" and "the person" do not. The ^ anchor signifies a string that begins with the characters that follow it. The characters ^ and $ are both considered to be anchors.
![filelocator pro regular expression tutorial filelocator pro regular expression tutorial](https://downloadbull.com/wp-content/uploads/2017/03/Download-Mythicsoft-FileLocator-Pro.jpg)
Now let's take a look at the components of a regex. To learn more, review the MDN Web Docs on the RegExp object. The constructor function's parameters are not enclosed within slashes instead, they use quotation marks. The second is to use a RegExp constructor.
![filelocator pro regular expression tutorial filelocator pro regular expression tutorial](https://progsoft.net/images/searchmyfiles-5c3307bf81b3287639ba71cb3de68730cd807d12.png)
The first, shown in our example, uses literal notation. Note: JavaScript provides two ways to create a regex object.