Main Restorations Software Audio/Jukebox/MP3 Everything Else Buy/Sell/Trade
Project Announcements Monitor/Video GroovyMAME Merit/JVL Touchscreen Meet Up Retail Vendors
Driving & Racing Woodworking Software Support Forums Consoles Project Arcade Reviews
Automated Projects Artwork Frontend Support Forums Pinball Forum Discussion Old Boards
Raspberry Pi & Dev Board controls.dat Linux Miscellaneous Arcade Wiki Discussion Old Archives
Lightguns Arcade1Up Try the site in https mode Site News

Unread posts | New Replies | Recent posts | Rules | Chatroom | Wiki | File Repository | RSS | Submit news

  

Author Topic: Does anyone use Regular Expressions much?  (Read 3134 times)

0 Members and 1 Guest are viewing this topic.

J_K_M_A_N

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 983
  • Last login:July 08, 2025, 08:22:37 am
Does anyone use Regular Expressions much?
« on: March 29, 2019, 12:09:25 am »
I have been getting into regular expressions for use with some small VB Net programs I sometimes write for work (mostly). I am pretty much a hack programmer, mostly self taught, so I am quite certain I did not learn many things the right way. Usually I can make it work though. We actually still use a program I wrote in VB6 15 years ago. That has saved some time over the years.  :o

I really like finding the patterns in data though and being able to rip what I need from that data. I made a program that gets entries from orders that customers send in and makes it so I can basically "auto enter" their orders in our software. Cuts down on order entry errors. :) Anyone else use them much? Any tips for cool things you have learned?

I recently learned the "match a pattern but don't capture" using (?:pattern). I also learned that you can look for a capture group inside of a non capturing group. Helpful for when there may or may not be some data inline with what you want. (My example is an address line 2...not always there.)

Also using [\r?\n|\r] for newline possibilities. I believe that will match \r\n, \n & \r which should be pretty much all new line characters possible (I think). Anyone else?

J_K_M_A_N

newmanfamilyvlogs

  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1694
  • Last login:June 15, 2022, 05:20:38 pm
    • forum.arcadecontrols.com/index.php/topic,103584.msg1096585.html#msg1096585
    • Newman Family Vlogs
Re: Does anyone use Regular Expressions much?
« Reply #1 on: March 29, 2019, 08:38:28 am »
I dabble with them occasionally, typically only for bulk text replacement or extraction, but never as part of a workflow solution. It's one of those tools I really would like to be more proficient at because they seem so versatile, but because I'm not using them every day I think I miss noticicing a lot of opportunities to use them and thereby learn them better.

I did use the RegEx find and replace in Notepad++ just a day ago to rip a list of links out of the Nasa Raw Images page for the InSight mission so I could wget a current set of the full mission images. I used
.*?((http(s?):)([/|.|\w|\s|-])*\.(?:png)+)
to capture any segment that looked like a link to a .png then replacement it with
$1\n

That gave me a nice list of URLs, where previously it was a single unbroken line of HTML that looked like this:
Code: [Select]
<li class="raw_image_container raw_image_container "><div class="raw_list_image" data-external-id="D000M0058_601662708EDR_F0000_0114M_"><div class="raw_list_image_inner"><a class="fancybox_slideshow" href="/raw_images/2854?site=insight" data-fancybox-group="images" data-fancybox-href="https://mars.nasa.gov/insight-raw-images/surface/sol/0058/idc/D000M0058_601662708EDR_F0000_0114M_.PNG" data-title="Sol 58: Instrument Deployment Camera (IDC)" data-sharedescription="" data-thumbnail="https://mars.nasa.gov/insight-raw-images/surface/sol/0058/idc/D000M0058_601662708EDR_F0000_0114M_.PNG" data-link="/raw_images/2854?site=insight" data-id="2854" data-external-id="D000M0058_601662708EDR_F0000_0114M_"></a><img src="https://mars.nasa.gov/insight-raw-images/surface/sol/0058/idc/D000M0058_601662708EDR_F0000_0114M_.PNG"></div></div></li><li class="raw_image_container raw_image_container "><div class="raw_list_image" data-external-id="C000M0056_601516832EDR_F0000_0461M_"><div class="raw_list_image_inner"><a class="fancybox_slideshow" href="/raw_images/3753?site=insight" data-fancybox-group="images" data-fancybox-href="https://mars.nasa.gov/insight-raw-images/surface/sol/0056/icc/C000M0056_601516832EDR_F0000_0461M_.PNG" data-title="Sol 56: Instrument Context Camera (ICC)" data-sharedescription="" data-thumbnail="https://mars.nasa.gov/insight-raw-images/surface/sol/0056/icc/C000M0056_601516832EDR_F0000_0461M_.PNG" data-link="/raw_images/3753?site=insight" data-id="3753" data-external-id="C000M0056_601516832EDR_F0000_0461M_"></a><img src="https://mars.nasa.gov/insight-raw-images/surface/sol/0056/icc/C000M0056_601516832EDR_F0000_0461M_.PNG"></div></div></li><li class="raw_image_container raw_image_container "><div class="raw_list_image" data-external-id="D050L0056_601516219EDR_F6262_0009M_"><div class="raw_list_image_inner"><a class="fancybox_slideshow" href="/raw_images/3771?site=insight" data-fancybox-group="images" data-fancybox-href="https://mars.nasa.gov/insight-raw-images/surface/sol/0056/idc/D050L0056_601516219EDR_F6262_0009M_.PNG" data-title="Sol 56: Instrument Deployment Camera (IDC)" data-sharedescription="" data-thumbnail="https://mars.nasa.gov/insight-raw-images/surface/sol/0056/idc/D050L0056_601516219EDR_F6262_0009M_.PNG" data-link="/raw_images/3771?site=insight" data-id="3771" data-external-id="D050L0056_601516219EDR_F6262_0009M_"></a><img src="https://mars.nasa.gov/insight-raw-images/surface/sol/0056/idc/D050L0056_601516219EDR_F6262_0009M_.PNG"></div></div></li>
Maybe someone should cook up an educational game where you learn RegEx by eliminating segments of text that drops down from the sky like Space Invaders... Or remove matching blocks of various colors of text to create matches like Candy Crush.

J_K_M_A_N

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 983
  • Last login:July 08, 2025, 08:22:37 am
Re: Does anyone use Regular Expressions much?
« Reply #2 on: March 29, 2019, 09:22:42 am »
Very nice solution. I use Notepad++ sometimes also. Nice editor. I usually test mine on this site which works well for VB Net.

http://regexstorm.net/tester

Usually, when it works in there, it will work in my program. I know some languages have some things that work differently like Java.

J_K_M_A_N

DrakeTungsten

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 287
  • Last login:August 14, 2022, 06:36:45 pm
  • I effed with the wrong person!
    • No Quarter - a basic FE, WIP
Re: Does anyone use Regular Expressions much?
« Reply #3 on: March 29, 2019, 12:03:43 pm »
Expresso is a cool tool for developing regular expressions. I mostly use it for checking my named capture groups. It's a big help.
« Last Edit: March 29, 2019, 12:08:06 pm by DrakeTungsten »
No Quarter - a basic FE, WIP

slickam

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 54
  • Last login:July 06, 2025, 09:00:54 pm
  • I want to build my own arcade controls!
Re: Does anyone use Regular Expressions much?
« Reply #4 on: March 29, 2019, 08:13:37 pm »
I've used them pretty heavily to parse and generate code. I've probably saved hundreds of hours at work by generating programs instead of writing them by hand.

Debuggex us a useful site to see diagrams of what your regular expression is doing.

surtr

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 26
  • Last login:May 01, 2019, 07:52:55 pm
  • I want to build my own arcade controls!
Re: Does anyone use Regular Expressions much?
« Reply #5 on: April 10, 2019, 10:21:28 am »
Just tossing another option out there, I use https://regexr.com/ and it has been outstanding.

J_K_M_A_N

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 983
  • Last login:July 08, 2025, 08:22:37 am
Re: Does anyone use Regular Expressions much?
« Reply #6 on: April 10, 2019, 12:38:51 pm »
Just tossing another option out there, I use https://regexr.com/ and it has been outstanding.

Thanks. I saved that one to my favorites. I love the reference available on the side. Very handy.

J_K_M_A_N

slickam

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 54
  • Last login:July 06, 2025, 09:00:54 pm
  • I want to build my own arcade controls!
Re: Does anyone use Regular Expressions much?
« Reply #7 on: April 10, 2019, 08:32:22 pm »
txt2re is another handy one. It lets you type in text, splits that into matches, and lets you build a regular expression by clicking either a specific value or a type of data.