Main > Everything Else |
Does anyone use Regular Expressions much? |
(1/2) > >> |
J_K_M_A_N:
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:
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: ---<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> --- End code --- 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:
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:
Expresso is a cool tool for developing regular expressions. I mostly use it for checking my named capture groups. It's a big help. |
slickam:
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. |
Navigation |
Message Index |
Next page |