After my first contact with a computer in the 1980's, I taught myself to program in BASIC and Z80 assembler. I went on to study Computer Science and have enjoyed a long career in Software Engineering.
Here are a couple of conventions I use when writing Regular Expressions to avoid some hazards:
1) Top & Tail: where appropriate (whole pattern matching) prefix the pattern with ^ and suffix with $ to limit the scope.
2) Limit repetition: Using {,n} and {1,n} instead of * and + for repeated groups/characters, when an upper limit (n) can be assumed. Even if n is a really big number it is usually better than unlimited.
I have also found it is just as important to confirm negative tests as positive tests. When confirming pattern make sure it not only matches the fragments of text you expect but also does not match text that is close but invalid.
A good learning/test resource I often refer to is regexr.com.
Here are a couple of conventions I use when writing Regular Expressions to avoid some hazards:
1) Top & Tail: where appropriate (whole pattern matching) prefix the pattern with ^ and suffix with $ to limit the scope.
2) Limit repetition: Using {,n} and {1,n} instead of * and + for repeated groups/characters, when an upper limit (n) can be assumed. Even if n is a really big number it is usually better than unlimited.
I have also found it is just as important to confirm negative tests as positive tests. When confirming pattern make sure it not only matches the fragments of text you expect but also does not match text that is close but invalid.
A good learning/test resource I often refer to is regexr.com.
Thank you for sharing :)