Find the ngDocs comments that have no methodOf (regex) - angularjs

I have built an angular1 application, which has thousands of methods in many many controllers, etc.
During the development, I wasn't too careful when creating docs comments. I have spent the night fixing the format to be able to generate docs, again.
Now I get this error message: Don't know how to format #ngdoc: method.
I have learned from other, similar questions, that this happens (or might happen), when the #methodOf attribute is missing. The Error message does not clarify where this happens.
So I'd like to find all those ngdoc comments, which are not properly formatted, using the IDEs (PhPStorm) search function and a regular expression.
This the current Expression, that I have come up with:
\/\*\*\s*\n\s\*\s#ngdoc method\n(\s\*.*(?<!methodOf)\n)*\s\*\/
From these comments, I'd like it to find the second one, only:
/**
* #ngdoc method
* #name app.admin:AuditLogController#auditsWatch
* #methodOf app.admin:AuditLogController
*/
/**
* #ngdoc method
* #name app.admin:AuditLogController#auditsWatch
*/
/**
* #name app.admin:AuditLogController#auditsWatch
*/
Test it here: https://regex101.com/r/wfIiZJ/1
So basically I'd like it to find any comment, that starts off with
/** and #ngdoc method, ends with */and does not have methodOf somewhere in between.
The closest I have come, is this one:
\/\*\*\s\n*.*(?!methodOf)\n*.*\n\s\*\/
https://regex101.com/r/qpt8G7/1
I'll continue trying, but maybe someone has the solution and is willing to share.
Any help here is greatly appreciated!

Okay, so right after I posted the question and thought it through from the beginning, I got the solution.
The regex looks like this:
(\/\*\*\s*\n\s*\*\s#ngdoc method\n)(((\s\*\s)(?!#methodOf).*\s*\n)*)\s*\*\/
https://regex101.com/r/Ep50XQ/1/
I divided it into several groups.
(\/\*\*\s*\n\s*\*\s#ngdoc method\n) finds
/**
* #ngdoc method
So any comment which documents a method.
(\s\*\s)
Takes care of a new comment line, consisting of possible white spaces, one *, followed by more whitespaces.
Here lies the culprit I fell into before.
I need to be aware of the current cursors position.
(?!#methodOf)
Makes sure the line does not start with #methodOf
In combination (((\s\*\s)(?!#methodOf).*\s*\n)*)
ensures a line within the comment, which does not start with #methodOf, can have any characters besides (.*), possibly some white spaces (\s) and ends with a line break. This can be repeated any number of times (*).
The last part
\s*\*\/
is this: */which ends the comment block and the regex.
Thank you, StackOverflow, for helping me think.
Maybe it can help somebody else, though.

You can make use of a tempered greedy token here:
(?s)\/\*\*\s*\*\s*#ngdoc method\n(?:(?!\*\/|methodOf).)*\s\*\/
^^^^^^^^^^^^^^^^^^^^^^^
See the regex demo
The pattern matches:
(?s) - enables . to match line breaks
\/\*\* - a literal /** substring
\s*\*\s* - a * enclosed with 0+ whitespaces
#ngdoc method\n - literal #ngdoc method substring followed with a newline
(?:(?!\*\/|methodOf).)* - the tempered greedy token matching any char, 0 or more times, that is not the starting point of a */ literal char sequence or methodOf substring
\s - a whitespace
\*\/ - a */ literal char sequence.
Note that you may consider using \R or \r?\n to match line breaks if there may be a CR before LF.

Related

regex with OR condition not working in angularjs [duplicate]

I'm creating a javascript regex to match queries in a search engine string. I am having a problem with alternation. I have the following regex:
.*baidu.com.*[/?].*wd{1}=
I want to be able to match strings that have the string 'word' or 'qw' in addition to 'wd', but everything I try is unsuccessful. I thought I would be able to do something like the following:
.*baidu.com.*[/?].*[wd|word|qw]{1}=
but it does not seem to work.
replace [wd|word|qw] with (wd|word|qw) or (?:wd|word|qw).
[] denotes character sets, () denotes logical groupings.
Your expression:
.*baidu.com.*[/?].*[wd|word|qw]{1}=
does need a few changes, including [wd|word|qw] to (wd|word|qw) and getting rid of the redundant {1}, like so:
.*baidu.com.*[/?].*(wd|word|qw)=
But you also need to understand that the first part of your expression (.*baidu.com.*[/?].*) will match baidu.com hello what spelling/handle????????? or hbaidu-com/ or even something like lkas----jhdf lkja$##!3hdsfbaidugcomlaksjhdf.[($?lakshf, because the dot (.) matches any character except newlines... to match a literal dot, you have to escape it with a backslash (like \.)
There are several approaches you could take to match things in a URL, but we could help you more if you tell us what you are trying to do or accomplish - perhaps regex is not the best solution or (EDIT) only part of the best solution?

Regular Expression Generation for AngularJS ng-pattern

I'm using a regex to validate a form input. So basically a user can input "SELECT some_name of select_match".
So far I have the regex: \bSELECT\b \bof select_match\b
The last part is the middle part, which I think should be [a-zA-Z] but I'm not sure how to place it in the middle. I've read multiple pages but can't get it to work.
Also preferably I'd like the regex to ignore spaces between "SELECT" and of "select_match". Meaning that SELECT blabla of select_match and SELECT blabla of select_match would both be validated as correct.
Can anyone tell me how to do this? Thank you.
If I understood you correctly, this should work:
/^SELECT\s+(\w+)\s+of select_match$/
Notes:
This allows any number of spaces between "SELECT" and the match_name; and between the match_name and the "of" (but, at least 1. To change to at least 0, change the \s+ to a \s*)
After that, the rest of the string must be exactly like that (same spaces and words exactly).
The match_name will be in match group 1.
If this doesn't work, show a bit of your code (where you use it) and we can try to find the problem.
Note: If you are using it in ng-pattern lose the "/"s (being the pattern: ^SELECT\s+(\w+)\s+of select_match$).
Note2: If you are using it in a string, remember you might need to escape every "\" (making it a "\", and the result: ^SELECT\\s+(\\w+)\\s+of select_match$

regex: extract text between two string with text that match a specific word

I'm refactorying a very big C project and I need to find out some part of code written by specific programmer.
Fortunately every guy involved in this project mark his own code using his email address in standard C style comments.
Ok, someone could say that this could be achieved easily with a grep from command line, but this is not my goal: I may need to remove this comments or substitute them with other text so regex is the only solution.
Ex.
/*********************************************
*
* ... some text ....
*
* author: user#domain.com
*
*********************************************/
From this post I found the right expression to search for C style comments which is:
\/\*(\*(?!\/)|[^*])*\*\/
But that is not enough! I only need the comments which contains a specific email address. Fortunately the domain of email address I'm looking for seems to be unique in the whole project so this could make it simpler.
I think I must use some positive lookahead assertion, I've tried this one:
(\/\*)(\*(?!\/)|[^*](?=.*domain.com))*(\*\/)
but it doesn't run!
Any advice?
You can use
\/\*[^*]*(?:\*(?!\/)[^*]*)*#domain\.com[^*]*(?:\*(?!\/)[^*]*)*\*\/
See the regex demo
Pattern details:
/\* - comment start
[^*]*(?:\*(?!\/)[^*]*)* - everything but */
#domain\.com - literal domain.com
[^*]*(?:\*(?!\/)[^*]*)* - everything but */
\*\/ - comment end
A faster alternative (as the first part will be looking for everything but the comment end and the word #domain):
\/\*[^*#]*(?:\*(?!\/)[^*#]*|#(?!domain\.com)[^*#]*)*#domain\.com[^*]*(?:\*(?!\/)[^*]*)*\*\/
See another demo
In these patterns, I used an unrolled construct for (\*(?!\/)|[^*])*: [^*]*(?:\*(?!\/)[^*]*)*. Unrolling helps construct more efficient patterns.

After adding snippit of code to default/setting.php bombarded by header warnings

I'm quite aware this question has been asked before multiple times, but I have no idea how to deal with this in my specfic situation. All I did was modify the default/settings.php file in order for the toolbar drawer in drupal to support more shortcuts.
I inserted the following code in the bottom of the document:
/**
* Changing Max Shortcut Slots
*
* The shortcut module supports a total of seven shortcuts slots. To change
* the quantity of supported enabled shortcuts the 'shortcut_max_slots' must be
* modified accordingly.
*
* #see https://www.drupal.org/documentation/modules/shortcut
*/
$conf['shortcut_max_slots'] = 11;
Well I got it to work, which is good, but I'm assaulted by a barrage of warnings, each one stating the following:
Warning: Cannot modify header information - headers already sent by (output started at /home/adamdcco/public_html/hadarc.com/cms/sites/default/settings.php:1) in drupal_send_headers() (line 1221 of /home/adamdcco/public_html/hadarc.com/cms/includes/bootstrap.inc).
I'm lost, I looked into the bootstrap file and navigated to the specficed line and, unfortunately no lightbulb. Sorry I'm new :), but I did search around, before being utterly overwhelmed
Any and all help is appreciated :P
Well than looks like we're good :)
I searched around some more and came across this question/answer
How to fix "Headers already sent" error in PHP , in a nutshell it's the same question, amazing answer, so yeah just in case anyone cared the code I inputted:
$conf['shortcut_max_slots'] = 11;
should of had quotes around the eleven, and any extra spaces in the beginning and in the end of the file had to be removed. Live and Learn :)

Regular expression to extract string in C Code (not inside comment)

I have this code in C but I only know how to extract string with regular expression that not inside comment code:
1. /* * "path_build()" function in "home.c" for more information.
2. * this is an example basic"
3. */
4.
5. /*** Free ***/
6. VALOR = string_make(format("%sxtra", libpath));
7. event_signal_string(EVENT_INITSTATUS, "Inicializando...");
should only return:
"%sxtra"
"Inicializando..."
I try:
".*"
but its don't work, it show me all text inside "", including the strings that inside /*...*/
I use EditPag Pro, RegExp panel.
It's a game translation project, I take the string of every C file and I translate to Spanish. I can't remove the comments of the original file.
The only thing I have clear is that this is the regex to find comments in C, maybe that will help the solution:
(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|(//.*)
Any help?
Edit: I put number of lines.
Hernaldo, this is an interesting question.
Here are two versions because I am not sure if you want to capture the "inside of the string" or "the whole string"
The regexps below capture the strings to capture Group 1. You completely ignore the overall match (Group 0) and just focus on Group 1. To retrieve the strings, just iterate over Group 1 matches in your language (discarding empty strings if any).
Version 1: "The inside of the string"
(?s)/\*.*?\*/|"([^"]+)"
This will capture %sxtra and Inicializando... to Group 1.
Version 2: "The whole string"
(?s)/\*.*?\*/|("[^"]+")
This will capture "%sxtra" and "Inicializando..." to Group 1.
Please let me know if you have any questions!
Note: I did not handle /* nested /* comments */ */ as that was not specified in the question. That would require a bit of tweaking and probably a regex engine supporting recursion.
The final solution for EditPad 6/7 is:
(?<!^[ \t]*/?[*#][^"\n]*")(?<=^[^"\n]*")[^"]+
Link:
Regular expression for a string that does not start with a /*

Resources