Insert Debug Code using Regular Expression
By this technique, we can find the function using regular expression and insert our debug code inside each function.Lets illustrate with a Javascript Source Code and Notepad++ IDE
Regular Expression to Find functions
Debug Code to insert inside each functions
Regular Expression to Insert Debug Code inside Functions
Javascript code after inserting Debug code using Regular Expression
Note: Please enable "Regular expression" and ". matches newline" in Search Mode in Replace box in Notepad++ for inserting inside more than 1 function using regular expression.
How this Regular Expression Works
\w |
All alphanumeric characters a-z, A-Z, 0-9 |
* |
Repeat the preceding character zero or many times |
\w* |
means any kind of names like "SyntaxHighlighter", "all" and not allowed are "Big Event", "get-Param" because it contains non alphanumeric characters like ' ' space, and '-' |
(\w*) |
means grouping it to a variable, the variable name is $1 or $2, or $3 depending on the order it is grouped. |
\s |
means any kind of space like ' ', or tab space, or new line, or carriage return |
\s* |
means any number of spaces or no space |
[ ] |
is to define a set of allowed characters sequence |
| |
means a conditional OR |
[:|=] |
means either ':' or '=' character |
\ |
Followed by a character means to either escape the special meaning of that character or it is to assign a special meaning to some normal characters. Like '\w' gives 'w' a special meaning to represent all alphanumeric characters and ‘\*' means to literally represent '*' |
\( \) \{ |
is to escape their special meaning and represent that character literally |
$1 |
is the 1st grouped variable and in our case "all: function(params) {" |
$2 |
is the 2nd grouped variable and in our case "SyntaxHighlighter", "all" |
No comments:
Post a Comment