What Regular expressions:
Regular expressions are ways to describe a piece of text(sequence of characters), in a way that a regular expression engine could understand.
Existing/Possible use cases of regular expressions:
- Finding information by specifying minimal text: For example in the ‘Find’/‘Find all’/‘Replace’/‘Replace all’ functionalities in text editors and in formulation of search queries in text-based search engines.
- Possible use cases:
- I have known that negative thoughts detrimental for mental health follow a template. Can that template be expressed as a regex? Could that be used to detect negative thoughts in real time and help rewire thinking patterns?
- If we convert music written by composers like Beethoven into a seuqneece of chords, can we express that sequence as a composer-specific regex or at least find recurring patterns?
- Generating information from templates:
- Possible use cases: Create a poem/haiku/songs/rap/puzzle/motivational-quotes from a regex template?
- Converting across text-based file types: To parse information and convert across mutliple file types, like, converting an age-old Shakespeare sonnet into an XML file for better processing.
- Possible use case: Generate a good pdf-parser, which is hard to find!
- For problems like spell checking, matching neucleotide sequences and spam filtering.
- Determining data quality
- Classifying text based on presence of matches with a regex:
- Clinical data classification using machine-generated regexes and constructive heuristic approach
- Quick classification of social media posts as COVID-19 or not
- Self-evolving regex for text classification
- Evolving classification regex with help of unlabeled data
- Possible Use cases: Tag a conversation as ‘whining’ based on its content?
- Checking against standard data formats: SSN/Credit card/password format checkers.
- Augmenting neural networks
Assignment2 statement
Design an exercise around regular expressions.
My attempt: ‘Poetry Shuffler – Causing chaos with poetry’
This is what the final code looks like:
1 | poem="\ |
Things I learnt along the way:
- I can write a poem anywhere and anytime.
- p5js
selectAll
method can be used to pick all p5Elements of a particular type. - One way to reset the background-color of an element over a white canvas, is to set it to white.
- Any global arrays that are being modified by a method (which could be called multiple times), need to be reset once that method is finished working, and in some cases, before it even starts.
- Random number picked using
Math.random()
would never be1
. Hence<length of an array>*Math.random()
is the correct qay to randomly pick an index from an array. - When using
replaceAll
method with a regex, need to appendgi
at the end of the regex, or you see the following error:TypeError: String.prototype.replaceAll called with a non-global RegExp argument
.
Open Questions:
- How does RiTa find rhyming words? Why does it not consider pores to rhyme with force?
Improvements that can be done to this:
- As always, the design. The green is really pricking my eyeballs. And the whole layout seems lifeless.
- This includes a poem template on which few modifications are made. Can we possibly generate an entirely new poem on the fly?
Takeaways:
- The only limit to creativity is your imagination .. and your mood schedule.