Cool Guide to Regular Expressions

Did you know you can use regular expressions (RegEx) in Hopscotch with the match block? RegEx is a powerful tool that lets you use a programming language to parse human language.

I saw this blog post and thought that some of the folks here might appreciate it. At least, I’ve been programming for over 12 years and I thought it was useful. Check it out: A Visual Guide to Regular Expression.

Reply here with any ideas of how you could use these in Hopscotch to make something cool!

30 Likes

thanks for the ideas!

I’ll try it out right now!

4 Likes

Ooh cool! I’ll check it out.

2 Likes

@AwesomeOnion do regex codes such as /s or /t work in the match block? As in, could we compare a string of text and find those sections or do we need to specific a certain portion of text and have it match in full?
As in,

Find any part:

‘a’
hello, how are you today?

Or, get the character at the first a’s index and directly compare to that one character?

6 Likes

Wait why do you seem so cool

1 Like

Wow I didn’t know that, All check it out later

1 Like

that’s helpful, cool

I also like this website for testing out RegEx

3 Likes

Yes, it has full JavaScript regular expression compatibility.


“Matches” is a Boolean – it returns 0 or 1.

I’d like to see a green “match” block (returns the actual matches, though HS does not have lists) and a replace block

6 Likes

Wow! Now I have to try it!

1 Like

Unfortunately that link is blocked on my school iPad :frowning:. I’ll be sure to check it out soon, though.

1 Like

Yes it is for mee

nice

Cool I’ll try that

Nice
And regex is the most confusing thing I have seen in programming
/(<**sw*[)—|^w]\n

2 Likes

gesundheit

3 Likes

Ooo this is very cool, thank you for sharing it with us!

3 Likes

I still cant understand reg ex

4 Likes

This guide seems helpful for visualising!

I also often use this site for testing out regular expressions.

https://regexr.com


Yeah it can seem quite confusing. Maybe using regexr to play around with a few of the examples from the guide may help.

I have some examples here:

This regex has the characters and, so it will match where those characters are next to each other (in that order). (It will match anywhere that and appears)

image

\b is for ‘word boundary’ (the start or end of a word — where a word character is next to a non-word character, I think).

If I add \b to the end of and, it will match anything that has the characters and and is followed by a word boundary. (So it will match anything that ends in ‘and’)

image

And if I had \b to the start of that, it will match anything that has a word boundary at the start, followed by the characters and, followed by a word boundary. (Now it will only match the word ‘and’)

image

(The website also has a reference on the left of the page, so you can check the different things that can be used. \b is just one of them)

10 Likes

Wow, thanks!
:D

1 Like

Wow ouch
And welcome back (lol you liked my projects recently)

1 Like