What is [50-99] in regular expression?

  • Thread starter Thread starter shivajikobardan
  • Start date Start date
  • Tags Tags
    Expression Regular
Click For Summary
SUMMARY

The regular expression notation [50-99] does not represent a range of numeric values but rather a character set that includes the individual characters '5', '0', '9', and any digit from '0' to '9'. This means that [50-99] can match characters like '5', '0', '9', and any digit, leading to unexpected matches such as '98888'. The correct interpretation of character ranges in regex is crucial for accurate pattern matching.

PREREQUISITES
  • Understanding of regular expression syntax
  • Familiarity with character sets and ranges in regex
  • Basic knowledge of string manipulation in programming
  • Experience with regex testing tools like Regexpal
NEXT STEPS
  • Explore regex character classes and ranges in depth
  • Learn about regex quantifiers and their applications
  • Practice using regex with real-world data validation scenarios
  • Enroll in online courses focused on regular expressions for backend development
USEFUL FOR

Backend developers, software engineers, and data analysts who need to implement and optimize regular expressions for data validation and parsing tasks.

shivajikobardan
Messages
637
Reaction score
54
TL;DR
regular expression character set meaning for [50-99]?
As the slide says, it's not 50-99 characters so what it is?

PDxPmiqvcz9UjWNJKyeZR2DyyMOULpLAZS0IaLfjCjF0kCR-sA.png

Source: https://www3.cs.stonybrook.edu/~pfodor/courses/CSE307/L02_Programming_RE.pdf

Also, please tell me how to learn regular expressions? Recommend some university/any courses to take for learning regular expression for backend development. (Not the one we learnt in theory of automata and computation).

There are lots of resources to learn it like regexpal for testing regular expressions, regexone.com for learning it. But how'd you learn it? Like what process do you follow to learn it?
 
Technology news on Phys.org
shivajikobardan said:
TL;DR Summary: regular expression character set meaning for [50-99]?

As the slide says, it's not 50-99 characters so what it is?
The answer is in the slide: [50-99] is the same as [0-9]. Why do you think this is?
[5] matches a 5, [9] matches a 9, [59] matches a 5 or a 9, [0-9] matches any character 0-9
shivajikobardan said:
regexone.com for learning it. But how'd you learn it? Like what process do you follow to learn it?
I had not seen https://regexone.com/ before: it looks really good so learn from that.
 
A key idea on the page about character ranges is this:
represent all characters between two characters
So 50 and 99 are not treated as numbers, but rather as a pair of characters each,
 
but I tried in regexpal, [50-99] matches number between 50-99 as well? @pbuk

edit: I'm wrong it also matches 98888
 
I got it. it's [5,0-9,9] that's why.
 
  • Like
Likes   Reactions: pbuk

Similar threads

  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 10 ·
Replies
10
Views
3K
Replies
1
Views
3K
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
29
Views
5K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 9 ·
Replies
9
Views
3K