Regular Expression OR Operator and Operator Precedence (aka the Alternation Operator)

preview_player
Показать описание
The OR operator allows you to compose regular expression patterns to match any one out of a set of alternative choices. The OR operator's precedence is lower than the AND THEN operator's. Using parenthesis to control the order of operations in a regular expression pattern, just like you do in algebraic expressions, is commonly useful when writing regular expressions that involve the OR operator. The OR operator is more technically referred to as the alternation or union operator.

A Mysterious, Little Course on Regular Expressions

This is the second video in "A Mysterious, Little Course on Regular Expressions", a short introductory course on applied regular expressions. The first video introduced the AND THEN (concatenation) operator and gave instructions for setting up your computer with Visual Studio Code and the course's project repository with the same files used in the video.

Instructions for Following Along:
2. In VSCode, Go to View, then Command Palette, type Git: Clone and press enter
4. Select the Folder/Directory you would like to save the project, press ok. Open the project.
5. In the Files Explorer Pane in VS Code, you should now see the three .txt files we're using in the videos:

About me: Hey, hey! I'm Kris Jordan (he/him/his), a professor who teaches computer science at the University of North Carolina at Chapel Hill. Back when I first tried to learn regular expressions it felt like a lot of weird, cryptic incantations to memorize. I couldn't separate the essential concepts to understand from the merely convenient shorthand add-ons. When I was was taught their theoretical basis, I struggled to connect academic notation and abstract examples with real-world syntax and concrete applications. So I'm teaching this for you the way I wish regular expressions were introduced to me: fundamentals-first with the syntax of modern applications in an actively hands-on, follow-along style.

If you enjoy learning, or being refreshed on, useful applications of fundamental ideas in computer science, data science, and software engineering, I encourage you to Subscribe to my channel so you can follow along as new lessons are added on a variety of subjects you'll find valuable!
Рекомендации по теме
Комментарии
Автор

For some reason I thought it would be more complicated than this. Thank you!

cc_snipergirl
Автор

hey! great video. nice audio and illustrating. thanks for it.
what is the software you are using to annotate on screen?

yash
Автор

11:20 > _"anything that was unclear in this video today"_

yes, what is your channel about in general?? like what type of content do you make? haha, i generally don't ask this question and see it for myself, but i just wanted to today. hope you wouldn't mind.

11:27 > _"content on ... computer science concepts"_

okay, got it 👍

yash
Автор

6:52 > _"pause ... and try"_

(I|J)(Q|O)(V|Y)4

* am i right? 7:38 yes
* are spaces allowed to make it readable?

yash
Автор

Is the combination of two strings like this: one, two -> otnweo, an example of alternation?

george_miller_
Автор

Random thought but regex gets messy fast. I used this regex today: "([^@"]+)@([^@"]+)",

Without context, it's very difficult to guess what's going on, but surprising, it wasn't terribly hard to write. It parses through a list of String constants that are quotes (the " and, are part of the regex), where each String ends with an @Someone (the person being quoted).

ericschneider