WillBridge0789 / ComicCraze-frontend

1 stars 1 forks source link

Prices are at the end of description field in "Comic" Table #9

Open WillBridge0789 opened 1 year ago

WillBridge0789 commented 1 year ago

Trying to show a price for each of the comics when rendered, however, the price is at the end of the comic description.

emberborja commented 1 year ago

This is a website that is a good resource for regex. I put in one of the comic descriptions in order to create a regex that can find a price within the larger text of the description.

https://regex101.com/r/lrmDRy/1

The good thing about that site is that if you hover over a rule it will show you what it does. You can also use the built in tools of the site to figure out what the different symbols in regex do and what is available.

[$]\d+[.]\d\d => this code looks like a literal $ symbol because it is wrapped in brackets "[$]", followed by a digit [0-9] match "\d", the "+" says 0-many of what it trails, so in this case it means $ followed by any number of digits. After any number of digits it will look for a period "[.]" and then it will try to match on exactly two digits.

You can play around with the data on that site and see what makes the regex break so you can account for edge cases.

For example, it will match on this => $19.99. It will find that out of the text and return what it matched. It can handle a comic that is hundred of dollars, but it will fail on this $19,000.99 and would fail on this $19.

You have ownership of your data so you can format it to be however you want. Making assumptions about your data means you can write less code on the frontend and it could result in code that is more performant.

emberborja commented 1 year ago

This is some handy documentation that explains reges: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Cheatsheet

emberborja commented 1 year ago

The regex could be used to determine price programmatically at render, for each comic. That would be a drain on performance. There are several approaches you can take to improve that though.