What are other regex examples?

0140

Here are some common regex examples along with their explanations:

  1. ^ (Start of a string):

    • Regex: ^Hello
    • Matches: Hello world, but not Say Hello.
  2. $ (End of a string):

    • Regex: world$
    • Matches: Hello world, but not world is big.
  3. . (Matches any single character):

    • Regex: a.b
    • Matches: aab, acb, but not ab (because it requires one character between a and b).
  4. * (Matches zero or more of the preceding element):

    • Regex: a*
    • Matches: ``, a, aa, aaa, but not b.
  5. + (Matches one or more of the preceding element):

    • Regex: a+
    • Matches: a, aa, aaa, but not b or ``.
  6. {n} (Matches exactly n occurrences):

    • Regex: a{3}
    • Matches: aaa, but not aa or aaaa.
  7. {n,} (Matches n or more occurrences):

    • Regex: a{2,}
    • Matches: aa, aaa, aaaa, but not a.
  8. {n,m} (Matches between n and m occurrences):

    • Regex: a{2,4}
    • Matches: aa, aaa, aaaa, but not a or aaaaa.
  9. | (Logical OR):

    • Regex: cat|dog
    • Matches: cat or dog, but not fish.
  10. [a-z] (Matches any lowercase letter):

    • Regex: [a-z]
    • Matches: a, b, c, ..., z.
  11. \d (Matches any digit):

    • Regex: \d
    • Matches: 0, 1, 2, ..., 9.
  12. \w (Matches any word character):

    • Regex: \w
    • Matches: any letter, digit, or underscore.
  13. \s (Matches any whitespace character):

    • Regex: \s
    • Matches: space, tab, newline.

These examples cover a range of common regex patterns. If you have specific use cases or need further examples, let me know!

0 Comments

no data
Be the first to share your comment!