3 ms·
The above is great advice. You will definitely want to play around with a tutorial, any tutorial, so you can grasp the basics of what regular expressions are, a
by Sakes 14y ago
The above is great advice. You will definitely want to play around with a tutorial, any tutorial, so you can grasp the basics of what regular expressions are, and how they are used. After you "get" what regular expressions are, you can work on implementing them in your code.
After you understand the basics, you can follow these steps that I use every time I need to program regular expressions.
1) Google a chart explaining the regular expression syntax for the language you are using (something like - applesscript regexp chart)
2) Create some test code to help refine your regular expression. Your code should have
* a - REGEX STRING - the regular expression value you are testing. You can store this value in a variable in your code, reference this value from a text file, or input it manually every time you run your script. I like to give myself access to this outside the code, so for a webpage have a form with an input field with this value. For scripting languages, make this a parameter of your script, so you can play with it quickly without having to change any code.
* b - STRING DATA - this is the value (or values) you will be comparing your regular expression against. You can store this in a variable, or reference this from a text file. Try and think of all cases that could potentially cause your script to break. For example, the currency symbols you are trying to replace, could they ever be used in ways where you would not want to replace them?
* c - RESULTS - you should output the results every time you run your script and keep tweaking it until you are satisfied with the output.
3) Implement your awesome REGEX in your code.